diff options
author | Gabriel Schulhof <gabriel.schulhof@intel.com> | 2017-08-24 13:33:26 +0300 |
---|---|---|
committer | Gabriel Schulhof <gabriel.schulhof@intel.com> | 2017-08-25 12:02:55 +0300 |
commit | 7efb8f7619100973877c660d0ee527ea3d92de8d (patch) | |
tree | 7b7d9f319f907713d3fa22cfd3d304ebbeeaac63 /src/node_api.h | |
parent | 64f59be62fcf55e6d0e7019ee61c712196c6914f (diff) | |
download | android-node-v8-7efb8f7619100973877c660d0ee527ea3d92de8d.tar.gz android-node-v8-7efb8f7619100973877c660d0ee527ea3d92de8d.tar.bz2 android-node-v8-7efb8f7619100973877c660d0ee527ea3d92de8d.zip |
n-api: implement promise
Promise is implemented as a pair of objects. `napi_create_promise()`
returns both a JavaScript promise and a newly allocated "deferred" in
its out-params. The deferred is linked to the promise such that the
deferred can be passed to `napi_resolve_deferred()` or
`napi_reject_deferred()` to reject/resolve the promise.
`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.
PR-URL: https://github.com/nodejs/node/pull/14365
Fixes: https://github.com/nodejs/abi-stable-node/issues/242
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Diffstat (limited to 'src/node_api.h')
-rw-r--r-- | src/node_api.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/node_api.h b/src/node_api.h index e52e2016d7..6a4b294187 100644 --- a/src/node_api.h +++ b/src/node_api.h @@ -543,6 +543,20 @@ NAPI_EXTERN napi_status napi_get_node_version(napi_env env, const napi_node_version** version); +// Promises +NAPI_EXTERN napi_status napi_create_promise(napi_env env, + napi_deferred* deferred, + napi_value* promise); +NAPI_EXTERN napi_status napi_resolve_deferred(napi_env env, + napi_deferred deferred, + napi_value resolution); +NAPI_EXTERN napi_status napi_reject_deferred(napi_env env, + napi_deferred deferred, + napi_value rejection); +NAPI_EXTERN napi_status napi_is_promise(napi_env env, + napi_value promise, + bool* is_promise); + EXTERN_C_END #endif // SRC_NODE_API_H_ |