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

Function TestWithTSFN

test/threadsafe_function/threadsafe_function_sum.cc:50–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50static Value TestWithTSFN(const CallbackInfo& info) {
51 int threadCount = info[0].As<Number>().Int32Value();
52 Function cb = info[1].As<Function>();
53
54 // We pass the test data to the Finalizer for cleanup. The finalizer is
55 // responsible for deleting this data as well.
56 TestData* testData = new TestData(Promise::Deferred::New(info.Env()));
57
58 ThreadSafeFunction tsfn = ThreadSafeFunction::New(
59 info.Env(),
60 cb,
61 "Test",
62 0,
63 threadCount,
64 std::function<decltype(FinalizerCallback)>(FinalizerCallback),
65 testData);
66
67 for (int i = 0; i < threadCount; ++i) {
68 // A copy of the ThreadSafeFunction will go to the thread entry point
69 testData->threads.push_back(std::thread(entryWithTSFN, tsfn, i));
70 }
71
72 return testData->deferred.Promise();
73}
74
75// Task instance created for each new std::thread
76class DelayedTSFNTask {

Callers

nothing calls this directly

Calls 2

EnvMethod · 0.80
PromiseMethod · 0.80

Tested by

no test coverage detected