setimmediate-napi

1.0.6 • Public • Published

setimmediate-napi

setImmediate() for N-API code

Greenkeeper badge

NPM Version NPM Downloads Build Status Coverage Status Dependency Status

Installation

Install with npm:

$ npm install setimmediate-napi

Usage

In your binding.gyp:

    'include_dirs'["<!@(node -p \"require('node-addon-api').include\")", 
                     "<!@(node -p \"require('setimmediate-napi').include\")"],

(Just have "<!@(node -p \"require('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 MakeCallback rather than Call to make sure Node.js can track your async context.
  • This function can be invoked even when executing JS code itself is not allowed.

/setimmediate-napi/

    Package Sidebar

    Install

    npm i setimmediate-napi

    Weekly Downloads

    46,143

    Version

    1.0.6

    License

    MIT

    Unpacked Size

    10.6 kB

    Total Files

    8

    Last publish

    Collaborators

    • addaleax