Skip to content

Commit

Permalink
doc: update napi_async_init documentation
Browse files Browse the repository at this point in the history
Fixes: nodejs#33153

Change documentation to make async_resource required
as opposed to optional in napi-async_init.

Changes over time mean this parameter is required for
proper operation of async hooks (which are still experimental).
This changes the documentation to document what
callers should do. We are doing this only in the doc
in order to avoid a breaking change in N-API. We could
create a new version of the method for which the
parametrer is enforced as mandatory but we should only
do that once async hooks is no longer experimental. In
that case we could deprecate (but not remove this version
of the method).

Signed-off-by: Michael Dawson <[email protected]>
  • Loading branch information
mhdawson committed Apr 30, 2020
1 parent 0413acc commit a62c146
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4672,7 +4672,7 @@ napi_status napi_async_init(napi_env env,
```

* `[in] env`: The environment that the API is invoked under.
* `[in] async_resource`: An optional object associated with the async work
* `[in] async_resource`: Object associated with the async work
that will be passed to possible `async_hooks` [`init` hooks][].
* `[in] async_resource_name`: Identifier for the kind of resource
that is being provided for diagnostic information exposed by the
Expand All @@ -4681,6 +4681,12 @@ napi_status napi_async_init(napi_env env,

Returns `napi_ok` if the API succeeded.

In order to retain ABI compatibility with previous versions,
passing `NULL` for `async_resource` will not result in an error, however,
this will result incorrect operation of async hooks for the
napi_async_context created. Potential issues include include
loss of async context when using the AsyncLocalStorage API.

### napi_async_destroy
<!-- YAML
added: v8.6.0
Expand Down

0 comments on commit a62c146

Please sign in to comment.