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

Integrate promirepl #49

Open
forivall opened this issue Jun 16, 2016 · 2 comments
Open

Integrate promirepl #49

forivall opened this issue Jun 16, 2016 · 2 comments

Comments

@forivall
Copy link
Contributor

https://github.com/building5/node-promirepl ❤️

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

@hems
Copy link

hems commented Feb 4, 2018

@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?

@hems
Copy link

hems commented Feb 4, 2018

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

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

No branches or pull requests

2 participants