Offload functions to worker threads with shared memory primitives for Node.js.
8
fork

Configure Feed

Select the types of activity you want to include in your feed.

test: error handling for dedicated and pool workers

+26
+23
test/error.test.ts
··· 1 + import { describe, it } from 'node:test'; 2 + import assert from 'node:assert/strict'; 3 + import { workerPool } from 'moroutine'; 4 + import { fail } from './fixtures/math.ts'; 5 + 6 + describe('error handling', () => { 7 + it('rejects with error from dedicated worker', async () => { 8 + await assert.rejects(() => fail('boom').then((x) => x), { 9 + message: 'boom', 10 + }); 11 + }); 12 + 13 + it('rejects with error from pool worker', async () => { 14 + const run = workerPool(1); 15 + try { 16 + await assert.rejects(() => run(fail('pool boom')), { 17 + message: 'pool boom', 18 + }); 19 + } finally { 20 + run[Symbol.dispose](); 21 + } 22 + }); 23 + });
+3
test/fixtures/math.ts
··· 2 2 3 3 export const double = mo(import.meta, (x: number) => 2 * x); 4 4 export const add = mo(import.meta, (a: number, b: number) => a + b); 5 + export const fail = mo(import.meta, (msg: string) => { 6 + throw new Error(msg); 7 + });