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 { workers } from 'moroutine';
4import { makeMultiplier, streamMultiplied } from './fixtures/stream-context.ts';
5
6describe('streaming with task-args', () => {
7 it('resolves task-args before streaming', async () => {
8 const factor = makeMultiplier(3);
9 const run = workers(1);
10 try {
11 const results: number[] = [];
12 for await (const value of run(streamMultiplied(factor, 4))) {
13 results.push(value);
14 }
15 assert.deepEqual(results, [0, 3, 6, 9]);
16 } finally {
17 run[Symbol.dispose]();
18 }
19 });
20});