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

Function TestAcquire

test/threadsafe_function/threadsafe_function_sum.cc:202–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200}
201
202static Value TestAcquire(const CallbackInfo& info) {
203 Function cb = info[0].As<Function>();
204 Napi::Env env = info.Env();
205
206 // We pass the test data to the Finalizer for cleanup. The finalizer is
207 // responsible for deleting this data as well.
208 TestData* testData = new TestData(Promise::Deferred::New(info.Env()));
209
210 testData->tsfn =
211 ThreadSafeFunction::New(env,
212 cb,
213 "Test",
214 0,
215 1,
216 testData,
217 std::function<decltype(AcquireFinalizerCallback)>(
218 AcquireFinalizerCallback),
219 testData);
220
221 Object result = Object::New(env);
222 result["createThread"] =
223 Function::New(env, CreateThread, "createThread", testData);
224 result["stopThreads"] =
225 Function::New(env, StopThreads, "stopThreads", testData);
226 result["promise"] = testData->deferred.Promise();
227
228 return result;
229}
230} // namespace
231
232Object InitThreadSafeFunctionSum(Env env) {

Callers

nothing calls this directly

Calls 2

EnvMethod · 0.80
PromiseMethod · 0.80

Tested by

no test coverage detected