(binding)
| 34 | const sum = (N) => N.reduce((sum, n) => sum + n, 0); |
| 35 | |
| 36 | function 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 | } |
nothing calls this directly
no test coverage detected