@napi-ffi/setimmediate-napi
v1.0.6
Published
`setImmediate()` for N-API code
Downloads
5
Readme
@napi-ffi/setimmediate-napi
setImmediate() for N-API code
Forked from node-ffi-napi/setimmediate-napi to maintain and modernize the project while preserving the original APIs.
Installation
Install with npm:
$ npm install @napi-ffi/setimmediate-napiUsage
In your binding.gyp:
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")",
"<!@(node -p \"require('@napi-ffi/setimmediate-napi').include\")"],(Just have "<!@(node -p \"require('@napi-ffi/setimmediate-napi').include\")" somewhere in that list, ok?)
In your C++ code:
#include <setimmediate.h>
int a = 10;
SetImmediate(env, [a]() {
/* do something with a ... */
});Keep in mind:
- You need to use
References to keep track of JS objects, since this code runs asynchronously. - Use
MakeCallbackrather thanCallto make sure Node.js can track your async context. - This function can be invoked even when executing JS code itself is not allowed.
