Offload functions to worker threads with shared memory primitives for Node.js.
1// Pipeline of streaming moroutines, each step on its own dedicated worker.
2// Data flows: generate → double → square → toString, all via MessageChannel.
3// Requires Node v24+.
4//
5// Run: node examples/pipeline/main.ts
6
7import { generate, double, square, toString } from './steps.ts';
8
9const numbers = generate(5);
10const doubled = double(numbers);
11const squared = square(doubled);
12const labels = toString(squared);
13
14for await (const label of labels) {
15 console.log(label);
16}
17// => 4
18// => 16
19// => 36
20// => 64
21// => 100