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 e46aca05dbf9a2204886d23f7ae3b34883f4e5c6 13 lines 407 B view raw
1// CPU-bound prime checking offloaded to a dedicated worker thread. 2// Requires Node v24+. 3// 4// Run: node examples/primes/main.ts 5 6import { isPrime } from './is-prime.ts'; 7 8const candidates = [999_999_937, 1_000_000_007, 1_000_000_009, 1_000_000_021, 1_000_000_033, 999_999_938]; 9 10for (const n of candidates) { 11 const prime = await isPrime(n); 12 console.log(`${n} is ${prime ? 'prime' : 'not prime'}`); 13}