summaryrefslogtreecommitdiff
path: root/src/node_api_types.h
diff options
context:
space:
mode:
authortaylor.woll <tawoll@ntdev.microsoft.com>2017-03-28 02:06:58 -0700
committerAnna Henningsen <anna@addaleax.net>2017-04-11 01:09:46 +0200
commit9decfb15215978b73094ffb7a4bdf2a0da010258 (patch)
treec49d73c4cd519aba60e7a86b7ea5779ac73d675f /src/node_api_types.h
parentca786c3734f6e23e34cd60f13e6bdaab033c5739 (diff)
downloadandroid-node-v8-9decfb15215978b73094ffb7a4bdf2a0da010258.tar.gz
android-node-v8-9decfb15215978b73094ffb7a4bdf2a0da010258.tar.bz2
android-node-v8-9decfb15215978b73094ffb7a4bdf2a0da010258.zip
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_types.h')
-rw-r--r--src/node_api_types.h47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/node_api_types.h b/src/node_api_types.h
index f439cce1f9..4bf1b82631 100644
--- a/src/node_api_types.h
+++ b/src/node_api_types.h
@@ -16,12 +16,7 @@ typedef struct napi_ref__ *napi_ref;
typedef struct napi_handle_scope__ *napi_handle_scope;
typedef struct napi_escapable_handle_scope__ *napi_escapable_handle_scope;
typedef struct napi_callback_info__ *napi_callback_info;
-
-typedef napi_value (*napi_callback)(napi_env env,
- napi_callback_info info);
-typedef void (*napi_finalize)(napi_env env,
- void* finalize_data,
- void* finalize_hint);
+typedef struct napi_async_work__ *napi_async_work;
typedef enum {
napi_default = 0,
@@ -34,20 +29,6 @@ typedef enum {
napi_static = 1 << 10,
} napi_property_attributes;
-typedef struct {
- // One of utf8name or name should be NULL.
- const char* utf8name;
- napi_value name;
-
- napi_callback method;
- napi_callback getter;
- napi_callback setter;
- napi_value value;
-
- napi_property_attributes attributes;
- void* data;
-} napi_property_descriptor;
-
typedef enum {
// ES6 types (corresponds to typeof)
napi_undefined,
@@ -85,9 +66,35 @@ typedef enum {
napi_array_expected,
napi_generic_failure,
napi_pending_exception,
+ napi_cancelled,
napi_status_last
} napi_status;
+typedef napi_value (*napi_callback)(napi_env env,
+ napi_callback_info info);
+typedef void (*napi_finalize)(napi_env env,
+ void* finalize_data,
+ void* finalize_hint);
+typedef void (*napi_async_execute_callback)(napi_env env,
+ void* data);
+typedef void (*napi_async_complete_callback)(napi_env env,
+ napi_status status,
+ void* data);
+
+typedef struct {
+ // One of utf8name or name should be NULL.
+ const char* utf8name;
+ napi_value name;
+
+ napi_callback method;
+ napi_callback getter;
+ napi_callback setter;
+ napi_value value;
+
+ napi_property_attributes attributes;
+ void* data;
+} napi_property_descriptor;
+
typedef struct {
const char* error_message;
void* engine_reserved;