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.

refactor: channel-fanout example uses assign() and run.workers

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+7 -4
+7 -4
examples/channel-fanout/main.ts
··· 4 4 // 5 5 // Run: node examples/channel-fanout/main.ts 6 6 7 - import { workers, channel } from '../../src/index.ts'; 7 + import { workers, channel, assign } from '../../src/index.ts'; 8 8 import { generate, process } from './work.ts'; 9 9 10 10 { 11 - using run = workers(4); 12 - const data = channel(generate(200)); 13 - const results: number[][] = await run([process(data), process(data), process(data), process(data)]); 11 + using run = workers(); 12 + const ch = channel(generate(200)); 13 + const fanout = run.workers.map((w) => { 14 + return assign(w, process(ch)); 15 + }); 16 + const results: number[][] = await run(fanout); 14 17 15 18 for (let i = 0; i < results.length; i++) { 16 19 console.log(`Worker ${i}: processed ${results[i].length} items`);