Skip to content

n-api: Context for custom async operations

  • Add napi_async_context opaque pointer type. (If needed, we could later add APIs for getting the async IDs out of this context.)
  • Add napi_async_init() and napi_async_destroy() APIs.
  • Add async_context parameter to napi_make_callback().
  • Add code and checks to test_make_callback to validate async context APIs by checking async hooks are called with correct context.
  • Update API documentation.

Fixes: https://github.com/nodejs/node/issues/13254

See also the related PR https://github.com/nodejs/node/pull/14697 in which napi_create_async_work() is updated to automatically track async context. That PR together with this one make up the complete story for async context tracking with N-API.

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