diff options
author | taylor.woll <tawoll@ntdev.microsoft.com> | 2017-03-28 02:06:58 -0700 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-04-11 01:09:46 +0200 |
commit | 9decfb15215978b73094ffb7a4bdf2a0da010258 (patch) | |
tree | c49d73c4cd519aba60e7a86b7ea5779ac73d675f /src/node_api.h | |
parent | ca786c3734f6e23e34cd60f13e6bdaab033c5739 (diff) | |
download | node-new-9decfb15215978b73094ffb7a4bdf2a0da010258.tar.gz |
n-api: implement async helper methods
Based on the async methods we had in abi-stable-node before the napi
feature landed in node/master. Changed this set of APIs to handle
error cases and removed a lot of the extra methods we had for setting
all the pieces of napi_work opting instead to pass all of those as
arguments to napi_create_async_work as none of those parameters are
optional except for the complete callback, anyway.
Renamed the napi_work struct to napi_async_work and replace the
struct itself with a class which can better encapsulate the object
lifetime and uv_work_t that we're trying to wrap anyway.
Added a napi_async_callback type for the async helper callbacks
instead of taking raw function pointers and make this callback take a
napi_env parameter as well as the void* data it was already taking.
Call the complete handler for the async work item with a napi_status
code translated from the uvlib error code.
The execute callback is required for napi_create_async_work, though
complete callback is still optional.
Also added some async unit tests for addons-napi based on the
addons/async_hello_world test.
PR-URL: https://github.com/nodejs/node/pull/12250
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Hitesh Kanwathirtha <hiteshk@microsoft.com>
Diffstat (limited to 'src/node_api.h')
-rw-r--r-- | src/node_api.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/node_api.h b/src/node_api.h index c232d9aa03..8791954a37 100644 --- a/src/node_api.h +++ b/src/node_api.h @@ -457,6 +457,21 @@ NAPI_EXTERN napi_status napi_get_typedarray_info(napi_env env, void** data, napi_value* arraybuffer, size_t* byte_offset); + +// Methods to manage simple async operations +NAPI_EXTERN +napi_status napi_create_async_work(napi_env env, + napi_async_execute_callback execute, + napi_async_complete_callback complete, + void* data, + napi_async_work* result); +NAPI_EXTERN napi_status napi_delete_async_work(napi_env env, + napi_async_work work); +NAPI_EXTERN napi_status napi_queue_async_work(napi_env env, + napi_async_work work); +NAPI_EXTERN napi_status napi_cancel_async_work(napi_env env, + napi_async_work work); + EXTERN_C_END #endif // SRC_NODE_API_H__ |