···22//
33// Run: node --experimental-strip-types examples/atomics/main.ts
4455-import { workerPool, int32atomic } from '../../src/index.ts';
55+import { pool, int32atomic } from '../../src/index.ts';
66import { increment } from './increment.ts';
7788const counter = int32atomic();
99-const pool = workerPool(4);
99+const run = pool(4);
10101111// Fire off 100 increments across 4 workers
1212-await Promise.all(Array.from({ length: 100 }, () => pool(increment(counter))));
1212+await Promise.all(Array.from({ length: 100 }, () => run(increment(counter))));
13131414-pool[Symbol.dispose]();
1414+run[Symbol.dispose]();
15151616console.log(`Expected: 100`);
1717console.log(`Actual: ${counter.load()}`);
+4-4
examples/non-blocking/main.ts
···33//
44// Run: node --experimental-strip-types examples/non-blocking/main.ts
5566-import { workerPool } from '../../src/index.ts';
66+import { pool } from '../../src/index.ts';
77import { fibonacci } from './fibonacci.ts';
8899// Tick a counter on the main thread to prove it's not blocked
···1616console.log('Computing fibonacci(42) on a worker pool...');
1717console.log('Meanwhile, the main thread keeps ticking:\n');
18181919-const pool = workerPool(2);
1919+const run = pool(2);
2020const start = performance.now();
2121-const [a, b] = await Promise.all([pool(fibonacci(42)), pool(fibonacci(41))]);
2121+const [a, b] = await Promise.all([run(fibonacci(42)), run(fibonacci(41))]);
2222const elapsed = (performance.now() - start).toFixed(0);
2323-pool[Symbol.dispose]();
2323+run[Symbol.dispose]();
24242525clearInterval(interval);
2626console.log(`\n\nResults: fib(42)=${a}, fib(41)=${b}`);
+4-4
examples/parallel-batch/main.ts
···33//
44// Run: node --experimental-strip-types examples/parallel-batch/main.ts
5566-import { workerPool } from '../../src/index.ts';
66+import { pool } from '../../src/index.ts';
77import { heavyWork } from './heavy-work.ts';
8899const items = Array.from({ length: 20 }, (_, i) => i + 1);
···20202121// Parallel: distribute across a pool of 4 workers
2222console.log('Parallel (worker pool, 4 workers)...');
2323-const pool = workerPool(4);
2323+const run = pool(4);
2424const parStart = performance.now();
2525-const parResults = await Promise.all(items.map((item) => pool(heavyWork(item))));
2525+const parResults = await Promise.all(items.map((item) => run(heavyWork(item))));
2626const parTime = (performance.now() - parStart).toFixed(0);
2727-pool[Symbol.dispose]();
2727+run[Symbol.dispose]();
2828console.log(` ${items.length} items in ${parTime}ms\n`);
29293030console.log(`Speedup: ~${(Number(seqTime) / Number(parTime)).toFixed(1)}x`);
+1-1
src/index.ts
···11export { mo } from './mo.ts';
22export { Task } from './task.ts';
33-export { workerPool } from './worker-pool.ts';
33+export { pool } from './worker-pool.ts';
44export { transfer } from './transfer.ts';
55export type { Runner } from './runner.ts';
66export {
+1-1
src/worker-pool.ts
···5566const workerEntryUrl = new URL('./worker-entry.ts', import.meta.url);
7788-export function workerPool(size: number): Runner {
88+export function pool(size: number): Runner {
99 const workers: Worker[] = [];
1010 for (let i = 0; i < size; i++) {
1111 const worker = new Worker(workerEntryUrl);
+2-2
test/error.test.ts
···11import { describe, it } from 'node:test';
22import assert from 'node:assert/strict';
33-import { workerPool } from 'moroutine';
33+import { pool } from 'moroutine';
44import { fail } from './fixtures/math.ts';
5566describe('error handling', () => {
···1111 });
12121313 it('rejects with error from pool worker', async () => {
1414- const run = workerPool(1);
1414+ const run = pool(1);
1515 try {
1616 await assert.rejects(() => run(fail('pool boom')), {
1717 message: 'pool boom',
+6-6
test/pool.test.ts
···11import { describe, it } from 'node:test';
22import assert from 'node:assert/strict';
33-import { workerPool } from 'moroutine';
33+import { pool } from 'moroutine';
44import { double, add } from './fixtures/math.ts';
5566-describe('workerPool', () => {
66+describe('pool', () => {
77 it('executes a moroutine through the pool', async () => {
88- const run = workerPool(2);
88+ const run = pool(2);
99 try {
1010 const result = await run(double(2));
1111 assert.equal(result, 4);
···1515 });
16161717 it('handles concurrent calls across pool workers', async () => {
1818- const run = workerPool(2);
1818+ const run = pool(2);
1919 try {
2020 const results = await Promise.all([run(double(1)), run(double(2)), run(double(3)), run(double(4))]);
2121 assert.deepEqual(results, [2, 4, 6, 8]);
···2525 });
26262727 it('handles multiple argument moroutines', async () => {
2828- const run = workerPool(1);
2828+ const run = pool(1);
2929 try {
3030 const result = await run(add(10, 20));
3131 assert.equal(result, 30);
···3535 });
36363737 it('dispose terminates pool workers', async () => {
3838- const run = workerPool(2);
3838+ const run = pool(2);
3939 await run(double(1));
4040 run[Symbol.dispose]();
4141 // After dispose, calls should fail