napi_add_async_cleanup_hook
NAPI_EXTERN napi_status napi_add_async_cleanup_hook(
node_api_basic_env env,
napi_async_cleanup_hook hook,
void* arg,
napi_async_cleanup_hook_handle* remove_handle); -
[in] env:调用 API 的环境。¥
[in] env: The environment that the API is invoked under. -
[in] hook:在环境拆卸时调用的函数指针。¥
[in] hook: The function pointer to call at environment teardown. -
[in] arg:调用时传递给hook的指针。¥
[in] arg: The pointer to pass tohookwhen it gets called. -
[out] remove_handle:引用异步清理钩子的可选句柄。¥
[out] remove_handle: Optional handle that refers to the asynchronous cleanup hook.
将 hook 注册为 napi_async_cleanup_hook 类型的函数,作为在当前 Node.js 环境退出后使用 remove_handle 和 arg 参数运行的函数。
¥Registers hook, which is a function of type napi_async_cleanup_hook, as
a function to be run with the remove_handle and arg parameters once the
current Node.js environment exits.
与 napi_add_env_cleanup_hook 不同的是,hook 允许是异步的。
¥Unlike napi_add_env_cleanup_hook, the hook is allowed to be asynchronous.
否则,行为通常与 napi_add_env_cleanup_hook 的行为相匹配。
¥Otherwise, behavior generally matches that of napi_add_env_cleanup_hook.
如果 remove_handle 不是 NULL,则将在其中存储一个不透明的值,该值稍后必须传递给 napi_remove_async_cleanup_hook,无论钩子是否已被调用。通常,当为其添加此钩子的资源无论如何都被拆除时,就会发生这种情况。
¥If remove_handle is not NULL, an opaque value will be stored in it
that must later be passed to napi_remove_async_cleanup_hook,
regardless of whether the hook has already been invoked.
Typically, that happens when the resource for which this hook was added
is being torn down anyway.