-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
replIssues and PRs related to the REPL subsystem.Issues and PRs related to the REPL subsystem.
Description
- 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:
var repl = require('repl'),
vm = require('vm');
function foo() {
return new Promise(function(resolve, reject) {
resolve({ success: true })
})
}
function myEval(code, context, file, cb) {
var res = vm.runInContext(code, context)
if (!res || typeof res.then != 'function') // Non-thenable response
return cb(null, res)
res.then(function(val) {
cb(null, val)
}, function(err) {
cb(err)
})
}
var replServer = repl.start({
eval: myEval
})
replServer.context.foo = foo;
And this is what happens:
> res = foo()
{ success: true }
> res.success
undefined
> res.constructor
[Function: Promise]
However, the "real" result does get correctly assigned to _
:
> res = foo()
{ success: true }
> _.success
true
Is there something I'm missing?
Thanks!
Metadata
Metadata
Assignees
Labels
replIssues and PRs related to the REPL subsystem.Issues and PRs related to the REPL subsystem.