Open forivall opened 8 years ago
@danielgtaylor how could we add a function to receive the evaluated value before returning the evaluated value to the shell?
Ideally, we would just check if it's a promise and if it's a promise we would "await" on it, I'm sure it wouldn't be complicated, it's just about "spoofing" the eval method?
That's how i worked it out:
nesh.start options, ( error, repl ) ->
# report error
if error then console.log nesh.log.error error
old_eval = repl.eval
repl.eval = ( input, context, filename, callback ) ->
old_eval input, context, filename, ( error, value ) ->
if error then return callback error
if value instanceof Promise
try
result = await value
return callback null, result
catch error
return callback error
callback error, value
https://github.com/building5/node-promirepl :heart:
I'll probably write a PR for this, since it's just mostly
copyingforking their code, and can be completely optional via the.promise
togglability