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.

at main 21 lines 784 B view raw
1// Moroutines from different modules running on a single worker. 2// The worker lazily imports each module the first time a task from it is dispatched. 3// Requires Node v24+. 4// 5// Run: node examples/multi-module/main.ts 6 7import { workers } from '../../src/index.ts'; 8import { square, add } from './math.ts'; 9import { uppercase, repeat } from './text.ts'; 10 11{ 12 using run = workers(1); 13 14 // All four moroutines from two modules run on the same single worker 15 const results = await run([square(7), add(3, 4), uppercase('hello'), repeat('ab', 3)]); 16 17 console.log('square(7) =', results[0]); // 49 18 console.log('add(3, 4) =', results[1]); // 7 19 console.log("uppercase('hello') =", results[2]); // HELLO 20 console.log("repeat('ab', 3) =", results[3]); // ababab 21}