File: threadsafe_function_ptr.cc

package info (click to toggle)
node-addon-api 8.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,256 kB
  • sloc: cpp: 15,585; javascript: 5,664; ansic: 157; makefile: 7
file content (27 lines) | stat: -rw-r--r-- 533 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "napi.h"

#if (NAPI_VERSION > 3)

using namespace Napi;

namespace {

static Value Test(const CallbackInfo& info) {
  Object resource = info[0].As<Object>();
  Function cb = info[1].As<Function>();
  ThreadSafeFunction tsfn =
      ThreadSafeFunction::New(info.Env(), cb, resource, "Test", 1, 1);
  tsfn.Release();
  return info.Env().Undefined();
}

}  // namespace

Object InitThreadSafeFunctionPtr(Env env) {
  Object exports = Object::New(env);
  exports["test"] = Function::New(env, Test);

  return exports;
}

#endif