napi_async_init
functionv1node_api.hIn order to retain ABI compatibility with previous versions, passing NULL for async_resource does not result in an error.
napi_status napi_async_init(napi_env env,
napi_value async_resource,
napi_value async_resource_name,
napi_async_context* result)
[in] env: The environment that the API is invoked under.[in] async_resource: Object associated with the async work that will be passed to possibleasync_hooksinithooks and can be accessed byasync_hooks.executionAsyncResource().[in] async_resource_name: Identifier for the kind of resource that is being provided for diagnostic information exposed by theasync_hooksAPI.[out] result: The initialized async context.
Returns napi_ok if the API succeeded.
In order to retain ABI compatibility with previous versions, passing NULL
for async_resource does not result in an error. However, this is not
recommended as this will result in undesirable behavior with async_hooks
init hooks and async_hooks.executionAsyncResource() as the resource is
now required by the underlying async_hooks implementation in order to provide
the linkage between async callbacks.
Previous versions of this API were not maintaining a strong reference to
async_resource while the napi_async_context object existed and instead
expected the caller to hold a strong reference. This has been changed, as a
corresponding call to napi_async_destroy for every call to
napi_async_init() is a requirement in any case to avoid memory leaks.