MCPcopy Index your code
hub / github.com/nodejs/node-addon-api / TestUnref

Function TestUnref

test/threadsafe_function/threadsafe_function_unref.cc:10–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8namespace {
9
10static Value TestUnref(const CallbackInfo& info) {
11 Napi::Env env = info.Env();
12 Object global = env.Global();
13 Object resource = info[0].As<Object>();
14 Function cb = info[1].As<Function>();
15 Function setTimeout = MaybeUnwrap(global.Get("setTimeout")).As<Function>();
16 ThreadSafeFunction* tsfn = new ThreadSafeFunction;
17
18 *tsfn = ThreadSafeFunction::New(
19 info.Env(), cb, resource, "Test", 1, 1, [tsfn](Napi::Env /* env */) {
20 delete tsfn;
21 });
22
23 tsfn->BlockingCall();
24
25 setTimeout.Call(
26 global,
27 {Function::New(
28 env, [tsfn](const CallbackInfo& info) { tsfn->Unref(info.Env()); }),
29 Number::New(env, 100)});
30
31 return info.Env().Undefined();
32}
33
34static Value TestRef(const CallbackInfo& info) {
35 Function cb = info[1].As<Function>();

Callers

nothing calls this directly

Calls 6

MaybeUnwrapFunction · 0.85
EnvMethod · 0.80
GetMethod · 0.80
BlockingCallMethod · 0.80
CallMethod · 0.80
UnrefMethod · 0.80

Tested by

no test coverage detected