diff --git a/package.json b/package.json index d28cb5e..d327e8a 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "release": "changeset version && changeset tag && git add -A && git commit -m \"chore: version $(node -p \"require('./package.json').version\")\" && git push --follow-tags", "lint": "prettier --check .", "lint:fix": "prettier --write .", - "test": "node --test --test-force-exit 'test/**/*.test.ts'" + "test": "node --test 'test/**/*.test.ts'" }, "devDependencies": { "@changesets/cli": "^2.30.0", diff --git a/src/worker-pool.ts b/src/worker-pool.ts index 2c3e374..8364f09 100644 --- a/src/worker-pool.ts +++ b/src/worker-pool.ts @@ -31,7 +31,7 @@ export function workers(size: number = availableParallelism(), opts?: WorkerOpti function track(promise: Promise): Promise { inflight.add(promise); - promise.finally(() => inflight.delete(promise)); + promise.finally(() => inflight.delete(promise)).catch(() => {}); return promise; } diff --git a/test/error.test.ts b/test/error.test.ts index 735f128..c21a19a 100644 --- a/test/error.test.ts +++ b/test/error.test.ts @@ -11,13 +11,9 @@ describe('error handling', () => { }); it('rejects with error from pool worker', async () => { - const run = workers(1); - try { - await assert.rejects(() => run(fail('pool boom')), { - message: 'pool boom', - }); - } finally { - run[Symbol.dispose](); - } + await using run = workers(1); + await assert.rejects(() => run(fail('pool boom')), { + message: 'pool boom', + }); }); }); diff --git a/test/fixtures/stream-context.ts b/test/fixtures/stream-context.ts new file mode 100644 index 0000000..4441bb8 --- /dev/null +++ b/test/fixtures/stream-context.ts @@ -0,0 +1,11 @@ +import { mo } from 'moroutine'; + +export const makeMultiplier = mo(import.meta, (factor: number): number => { + return factor; +}); + +export const streamMultiplied = mo(import.meta, async function* (factor: number, count: number) { + for (let i = 0; i < count; i++) { + yield i * factor; + } +}); diff --git a/test/fixtures/stream-pipeline.ts b/test/fixtures/stream-pipeline.ts new file mode 100644 index 0000000..58b8e73 --- /dev/null +++ b/test/fixtures/stream-pipeline.ts @@ -0,0 +1,13 @@ +import { mo } from 'moroutine'; + +export const generate = mo(import.meta, async function* (n: number) { + for (let i = 1; i <= n; i++) yield i; +}); + +export const double = mo(import.meta, async function* (input: AsyncIterable) { + for await (const n of input) yield n * 2; +}); + +export const square = mo(import.meta, async function* (input: AsyncIterable) { + for await (const n of input) yield n * n; +}); diff --git a/test/stream-context.test.ts b/test/stream-context.test.ts index d1a4f97..ddc7da5 100644 --- a/test/stream-context.test.ts +++ b/test/stream-context.test.ts @@ -1,16 +1,7 @@ import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; -import { mo, workers } from 'moroutine'; - -const makeMultiplier = mo(import.meta, (factor: number): number => { - return factor; -}); - -const streamMultiplied = mo(import.meta, async function* (factor: number, count: number) { - for (let i = 0; i < count; i++) { - yield i * factor; - } -}); +import { workers } from 'moroutine'; +import { makeMultiplier, streamMultiplied } from './fixtures/stream-context.ts'; describe('streaming with task-args', () => { it('resolves task-args before streaming', async () => { diff --git a/test/stream-pipeline.test.ts b/test/stream-pipeline.test.ts index e46c6eb..c317fca 100644 --- a/test/stream-pipeline.test.ts +++ b/test/stream-pipeline.test.ts @@ -1,18 +1,7 @@ import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; -import { mo, channel } from 'moroutine'; - -const generate = mo(import.meta, async function* (n: number) { - for (let i = 1; i <= n; i++) yield i; -}); - -const double = mo(import.meta, async function* (input: AsyncIterable) { - for await (const n of input) yield n * 2; -}); - -const square = mo(import.meta, async function* (input: AsyncIterable) { - for await (const n of input) yield n * n; -}); +import { channel } from 'moroutine'; +import { generate, double, square } from './fixtures/stream-pipeline.ts'; describe('streaming pipeline', () => { it('chains two streaming moroutines', async () => {