napi_add_async_cleanup_hook
functionv8node_api.hRegisters 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_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: The environment that the API is invoked under.[in] hook: The function pointer to call at environment teardown.[in] arg: The pointer to pass tohookwhen it gets called.[out] remove_handle: Optional handle that refers to the asynchronous cleanup hook.
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.
Unlike napi_add_env_cleanup_hook, the hook is allowed to be asynchronous.
Otherwise, behavior generally matches that of napi_add_env_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.