diff --git a/README.md b/README.md index 23fd7d4..121d1b4 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ import { workers, leastBusy } from 'moroutine'; ``` Built-in balancers: + - `roundRobin()` — cycles through workers in order (default) - `leastBusy()` — picks the worker with the lowest active task count diff --git a/src/dedicated-runner.ts b/src/dedicated-runner.ts index 3dbb7ce..cd4b49a 100644 --- a/src/dedicated-runner.ts +++ b/src/dedicated-runner.ts @@ -48,6 +48,9 @@ export function runStreamOnDedicated(id: string, args: unknown[]): AsyncItera const worker = getWorker(id); ref(worker); const { iterable, done } = dispatchStream(worker, id, args); - done.then(() => unref(worker), () => unref(worker)); + done.then( + () => unref(worker), + () => unref(worker), + ); return iterable; } diff --git a/test/fixtures/load-balancing.ts b/test/fixtures/load-balancing.ts index fb08d4c..df4dda0 100644 --- a/test/fixtures/load-balancing.ts +++ b/test/fixtures/load-balancing.ts @@ -10,6 +10,8 @@ export const slow = mo(import.meta, async (ms: number): Promise => { export const busy = mo(import.meta, (ms: number): string => { const start = Date.now(); - while (Date.now() - start < ms) { /* busy wait */ } + while (Date.now() - start < ms) { + /* busy wait */ + } return 'done'; }); diff --git a/test/load-balancing.test.ts b/test/load-balancing.test.ts index 190a173..4385e5b 100644 --- a/test/load-balancing.test.ts +++ b/test/load-balancing.test.ts @@ -80,8 +80,12 @@ describe('load balancing', () => { it('balancer dispose is called on sync dispose', () => { let disposed = false; const custom: Balancer = { - select(workers) { return workers[0]; }, - [Symbol.dispose]() { disposed = true; }, + select(workers) { + return workers[0]; + }, + [Symbol.dispose]() { + disposed = true; + }, }; const run = workers(1, { balance: custom }); run[Symbol.dispose](); @@ -91,8 +95,12 @@ describe('load balancing', () => { it('balancer asyncDispose is called on async dispose', async () => { let disposed = false; const custom: Balancer = { - select(workers) { return workers[0]; }, - async [Symbol.asyncDispose]() { disposed = true; }, + select(workers) { + return workers[0]; + }, + async [Symbol.asyncDispose]() { + disposed = true; + }, }; const run = workers(1, { balance: custom }); await run[Symbol.asyncDispose](); @@ -102,7 +110,10 @@ describe('load balancing', () => { it('pinned tasks bypass balancer', async () => { let called = false; const custom: Balancer = { - select(workers) { called = true; return workers[0]; }, + select(workers) { + called = true; + return workers[0]; + }, }; const run = workers(2, { balance: custom }); try { diff --git a/test/pool-ref.test.ts b/test/pool-ref.test.ts index 327462f..efc90f1 100644 --- a/test/pool-ref.test.ts +++ b/test/pool-ref.test.ts @@ -10,11 +10,9 @@ const fixturesDir = join(fileURLToPath(import.meta.url), '..', 'fixtures'); describe('pool worker ref behavior', () => { it('pool keeps event loop alive for top-level await', async () => { - const { stdout } = await exec( - process.execPath, - ['--no-warnings', join(fixturesDir, 'pool-ref-main.ts')], - { timeout: 5000 }, - ); + const { stdout } = await exec(process.execPath, ['--no-warnings', join(fixturesDir, 'pool-ref-main.ts')], { + timeout: 5000, + }); assert.ok(stdout.includes('DONE')); }); });