- Version: v8.9.4
- Platform: Linux x64
- Subsystem: repl
I'm trying to build a custom repl that yields promises before returning the value to the user, but for some reason I'm unable to "reach" the final value, even though it does appear to be correctly assigned.
This is the code I'm using:
varrepl=require('repl'),vm=require('vm');functionfoo(){returnnewPromise(function(resolve,reject){resolve({success: true})})}functionmyEval(code,context,file,cb){varres=vm.runInContext(code,context)if(!res||typeofres.then!='function')// Non-thenable responsereturncb(null,res)res.then(function(val){cb(null,val)},function(err){cb(err)})}varreplServer=repl.start({eval: myEval})replServer.context.foo=foo;And this is what happens:
>res=foo(){success: true}>res.successundefined>res.constructor[Function: Promise]However, the "real" result does get correctly assigned to _:
>res=foo(){success: true}>_.successtrueIs there something I'm missing?
Thanks!
I'm trying to build a custom repl that yields promises before returning the value to the user, but for some reason I'm unable to "reach" the final value, even though it does appear to be correctly assigned.
This is the code I'm using:
And this is what happens:
However, the "real" result does get correctly assigned to
_:Is there something I'm missing?
Thanks!