Something went wrong. Try again.
Offload functions to worker threads with shared memory primitives for Node.js.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445import { describe, it } from 'node:test';import assert from 'node:assert/strict';import { workers } from 'moroutine';import { double, add } from './fixtures/math.ts';
describe('workers', () => { it('executes a moroutine through the pool', async () => { const run = workers(2); try { const result = await run(double(2)); assert.equal(result, 4); } finally { run[Symbol.dispose](); } });
it('handles concurrent calls across pool workers', async () => { const run = workers(2); try { const results = await run([double(1), double(2), double(3), double(4)]); assert.deepEqual(results, [2, 4, 6, 8]); } finally { run[Symbol.dispose](); } });
it('handles multiple argument moroutines', async () => { const run = workers(1); try { const result = await run(add(10, 20)); assert.equal(result, 30); } finally { run[Symbol.dispose](); } });
it('dispose terminates pool workers', async () => { const run = workers(2); await run(double(1)); run[Symbol.dispose](); // After dispose, calls should fail await assert.rejects(() => run(double(1))); });});