Skip to content

n-api: implement async helper methods

Rodrigo Muino Tomonari requested to merge github/fork/boingoing/async_api into master

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.

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

n-api

Merge request reports

Loading