Offload functions to worker threads with shared memory primitives for Node.js.
1import { describe, it } from 'node:test';
2import assert from 'node:assert/strict';
3import { double, add } from './fixtures/math.ts';
4
5describe('dedicated runner', () => {
6 it('executes a moroutine on a worker thread', async () => {
7 const result = await double(2);
8 assert.equal(result, 4);
9 });
10
11 it('handles multiple arguments', async () => {
12 const result = await add(3, 4);
13 assert.equal(result, 7);
14 });
15
16 it('handles sequential calls', async () => {
17 const a = await double(5);
18 const b = await double(10);
19 assert.equal(a, 10);
20 assert.equal(b, 20);
21 });
22
23 it('handles concurrent calls', async () => {
24 const results = await Promise.all([double(1), double(2), double(3)]);
25 assert.deepEqual(results, [2, 4, 6]);
26 });
27});