Offload functions to worker threads with shared memory primitives for Node.js.
1import { workers } from 'moroutine';
2import { busy } from './load-balancing.ts';
3
4// Dispatches CPU-bound tasks on a dedicated worker, then on a pool.
5// The process should complete and print DONE; if pool workers
6// are unref'd the event loop may exit early (exit code 13).
7
8await busy(10);
9
10{
11 using run = workers(2);
12 const results = await run([busy(50), busy(50), busy(50)]);
13 console.log('DONE ' + results.join(','));
14}