MCPcopy Create free account
hub / github.com/nodejs/node-addon-api / test

Function test

test/threadsafe_function/threadsafe_function_sum.js:36–59  ·  view source on GitHub ↗
(binding)

Source from the content-addressed store, hash-verified

34const sum = (N) => N.reduce((sum, n) => sum + n, 0);
35
36function test (binding) {
37 async function check (bindingFunction) {
38 const calls = [];
39 const result = await bindingFunction(THREAD_COUNT, Array.prototype.push.bind(calls));
40 assert.ok(result);
41 assert.equal(sum(calls), EXPECTED_SUM);
42 }
43
44 async function checkAcquire () {
45 const calls = [];
46 const { promise, createThread, stopThreads } = binding.threadsafe_function_sum.testAcquire(Array.prototype.push.bind(calls));
47 for (let i = 0; i < THREAD_COUNT; i++) {
48 createThread();
49 }
50 stopThreads();
51 const result = await promise;
52 assert.ok(result);
53 assert.equal(sum(calls), EXPECTED_SUM);
54 }
55
56 return check(binding.threadsafe_function_sum.testDelayedTSFN)
57 .then(() => check(binding.threadsafe_function_sum.testWithTSFN))
58 .then(() => checkAcquire());
59}

Callers

nothing calls this directly

Calls 2

checkFunction · 0.70
checkAcquireFunction · 0.70

Tested by

no test coverage detected