Skip to content

n-api: implement promise

Promise is implemented as a pair of objects. napi_create_promise() returns both a JavaScript promise and a "deferred" in its out-params. The deferred is linked to the promise such that the deferred can be passed to napi_conclude_deferred() to rejct/resolve the promise. The deferred is a valid JavaScript value, but it is a shell object offering no useful JavaScript functionality. In contrast, the promise returned by napi_create_promise() is a full-fledged native JavaScript Promise which can be used for chaining in JavaScript.

napi_is_promise() can be used to check if a napi_value is a native promise - that is, a promise created by the underlying engine, rather than a pure JS implementation of a promise.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

n-api

Merge request reports

Loading