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.

chore: update atomics example to use AtomicInt32

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

+25
+6
examples/atomics/increment.ts
··· 1 + import { mo } from '../../src/index.ts'; 2 + import type { AtomicInt32 } from '../../src/index.ts'; 3 + 4 + export const increment = mo(import.meta, (counter: AtomicInt32): number => { 5 + return counter.add(1); 6 + });
+19
examples/atomics/main.ts
··· 1 + // Shared memory between main thread and workers using AtomicInt32. 2 + // 3 + // Run: node --experimental-strip-types examples/atomics/main.ts 4 + 5 + import { workerPool, AtomicInt32 } from '../../src/index.ts'; 6 + import { increment } from './increment.ts'; 7 + 8 + const counter = new AtomicInt32(); 9 + const pool = workerPool(4); 10 + 11 + // Fire off 100 increments across 4 workers 12 + await Promise.all( 13 + Array.from({ length: 100 }, () => pool(increment(counter))), 14 + ); 15 + 16 + pool[Symbol.dispose](); 17 + 18 + console.log(`Expected: 100`); 19 + console.log(`Actual: ${counter.load()}`);