Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_node client does not properly wait for async functions when code pasted in #356

Open
michael-ts opened this issue Mar 28, 2017 · 6 comments

Comments

@michael-ts
Copy link

michael-ts commented Mar 28, 2017

I'm testing some code by copy/pasting from an editor into _node. What I am finding is that when I do this, code on one line does not finish executing before _node tries to run the next command.

Here is a simple example in action. First, I initialize a small sqlite3 database:

var sqlite3=require("sqlite3")
var db=new sqlite3.Database("test")
db.exec("CREATE TABLE test(name TEXT)",_)
db.exec("INSERT INTO test(name) VALUES ('test')",_)
db.close()

Now I exit and restart _node and paste in the following code:

var sqlite3=require("sqlite3")
var db=new sqlite3.Database("test")
var x=db.all("SELECT * FROM test",_)
console.log(x.name)

Since the call to db.all is streamlined, I would expect the variable "x" to have a value before the next line. However, here is the actual output:

$ _node
_node> var sqlite3=require("sqlite3")
undefined
_node> var db=new sqlite3.Database("test")
undefined
_node> var x=db.get("SELECT * FROM test",_)
console.log(x.name)
TypeError: Cannot read property 'name' of undefined
    at _$$$$ (repl:8:25)
    at applyFast (/Users/michael/node/node_modules/streamline-runtime/lib/fibers/runtime.js:14:21)
    at __streamline$run (eval at makeTransform (/Users/michael/node/node_modules/streamline-runtime/lib/fibers/runtime.js:151:128), <anonymous>:30:11)
_node> undefined

@michael-ts
Copy link
Author

I am also seeing this behavior if I try to .load code, so it doesn't seem to be directly related to copy/paste:

$ _node
_node> .load test2.js
_node> var sqlite3=require("sqlite3")
undefined
_node> var db=new sqlite3.Database("test")
undefined
_node> var x=db.get("SELECT * FROM test",_)
console.log(x.name)
TypeError: Cannot read property 'name' of undefined
    at _$$$$ (repl:8:25)
    at applyFast (/Users/michael/node/node_modules/streamline-runtime/lib/fibers/runtime.js:14:21)
    at __streamline$run (eval at makeTransform (/Users/michael/node/node_modules/streamline-runtime/lib/fibers/runtime.js:151:128), <anonymous>:30:11)
_node> undefined
_node> x.name
'test'
_node>

@bjouhier
Copy link
Member

I tested it on OS/X and did not reproduce. What is your OS?

@michael-ts
Copy link
Author

I have been able to reproduce it both on OS X and Windows (Ubuntu subsystem).

@bjouhier
Copy link
Member

I tested with node 6.10.1. I tried with:

function foo(_, val) { setTimeout(_, 10); return val; }
var x = foo(_, "abc")
console.log(x)

On the other hand I got an error when hitting on an empty line.

@bjouhier
Copy link
Member

I did the copy paste several times and did not watch carefully. Actually, I see the problem the first time!

@bjouhier
Copy link
Member

I've fixed the node 6 issue with empty lines but I haven't fixed this one.

This issue may be hard to fix because of the way REPL variables are managed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants