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

Closed
dherman opened this issue Apr 21, 2016 · 5 comments
Closed

Promise API #73

dherman opened this issue Apr 21, 2016 · 5 comments

Comments

@dherman
Copy link
Collaborator

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
Copy link

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

@pitaj
Copy link

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

@cdbattags
Copy link

Any update here with rust 1.39, future 0.3 and tokio 0.2 release?

Would love to do some experimentation wiring express.js controllers and actix-web services

@bochaco
Copy link

bochaco commented Jan 16, 2020

I was also wondering the same, I am looking for a way to bind async functions to JS Promises

@dherman
Copy link
Collaborator Author

dherman commented Sep 15, 2021

This has a great v1 design for promises in RFC neon-bindings/rfcs#35. 🎉

@dherman dherman closed this as completed Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants