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

Promise API #73

Open
dherman opened this issue Apr 21, 2016 · 2 comments

Comments

@dherman
Copy link
Collaborator

@dherman dherman commented Apr 21, 2016

Expose the Promise object type under neon::js::promise::JsPromise, using v8::Promise. This one is going to require some good experimentation and thinking around the neon async story (see #26).

@winding-lines

This comment has been minimized.

Copy link

@winding-lines winding-lines commented Jul 22, 2016

@dherman I finally have some time to play with neon, will check this out :)

@pitaj

This comment has been minimized.

Copy link

@pitaj pitaj commented Jul 15, 2018

Just a few resources people might find handy if they want to try implementing this:

Some other things to consider:

  • Rust will soon? have first-class Future support, it would be good to provide an API to convert a Rust Future to a JS Promise
  • As said in the example

    Node.js will process the fulfillment/conclusion of the Promise in an asynchronous fashion (compared to "real-time" in JavaScript) because the fulfillment is added to the event loop's "Promise fulfillment microtask queue", which is processed immediately after the "nextTick microtask queue", even when it is fulfilled synchronously in C++.

    If this ever becomes UNTRUE, then you would need to utilize an AsyncWorker (or a similar concept) in order to ensure this Promise is fulfilled asynchronously.

  • Since the N-API is available since Node 8, it is worth considering supporting it for all Node versions >=8, with instead instructing developers to use a callback native API with a Promise on the JS side for versions older than that. Node 6 has less than a year of maintenance support left, after all.
  • If that is not acceptable, then perhaps it is possible to automate doing that instead, or to provide a Promise through older C++ APIs. I'm unaware of nan supporting Promise creation though, so it would require more direct V8 APIs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.