Neon: Promise API

Created on 22 Apr 2016  路  4Comments  路  Source: neon-bindings/neon

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).

API Triaged beginner friendly requires javascript requires safe rust requires unsafe rust requires v8 c++

Most helpful comment

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

All 4 comments

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

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cookiengineer picture cookiengineer  路  3Comments

hardliner66 picture hardliner66  路  3Comments

leshow picture leshow  路  3Comments

chpio picture chpio  路  6Comments

crazyfrozenpenguin picture crazyfrozenpenguin  路  3Comments