diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-07-31 03:10:14 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-08-07 01:02:02 +0300 |
commit | 22cbbcf9d9374d4b663bf1409f292212fa57623a (patch) | |
tree | 59a9e22bdae3900b961e4c58f53aa6c9b0a511bd /src/node.h | |
parent | a4e1755df2f9bb8c712d7ca767a5944d9d71e33b (diff) |
n-api,src: provide asynchronous cleanup hooks
Sometimes addons need to perform cleanup actions, for example
closing libuv handles or waiting for requests to finish, that
cannot be performed synchronously.
Add C++ API and N-API functions that allow providing such
asynchronous cleanup hooks.
Fixes: https://github.com/nodejs/node/issues/34567
PR-URL: https://github.com/nodejs/node/pull/34572
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Diffstat (limited to 'src/node.h')
-rw-r--r-- | src/node.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/node.h b/src/node.h index c84a16a01a4..d2c1b9cff34 100644 --- a/src/node.h +++ b/src/node.h @@ -867,6 +867,20 @@ NODE_EXTERN void RemoveEnvironmentCleanupHook(v8::Isolate* isolate, void (*fun)(void* arg), void* arg); +/* These are async equivalents of the above. After the cleanup hook is invoked, + * `cb(cbarg)` *must* be called, and attempting to remove the cleanup hook will + * have no effect. */ +struct ACHHandle; +struct NODE_EXTERN DeleteACHHandle { void operator()(ACHHandle*) const; }; +typedef std::unique_ptr<ACHHandle, DeleteACHHandle> AsyncCleanupHookHandle; + +NODE_EXTERN AsyncCleanupHookHandle AddEnvironmentCleanupHook( + v8::Isolate* isolate, + void (*fun)(void* arg, void (*cb)(void*), void* cbarg), + void* arg); + +NODE_EXTERN void RemoveEnvironmentCleanupHook(AsyncCleanupHookHandle holder); + /* Returns the id of the current execution context. If the return value is * zero then no execution has been set. This will happen if the user handles * I/O from native code. */ |