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 e2cebd539403475e2f4e79d55ca1a84a0ce3510d 16 lines 527 B view raw
1import { mo } from '../../src/index.ts'; 2 3// Each worker thread loads this module and gets its own `counts` map. 4// Affinity routing keeps all operations on a given key on the same worker 5// so the count is consistent. 6const counts = new Map<string, number>(); 7 8export const increment = mo(import.meta, (key: string, n: number): number => { 9 const next = (counts.get(key) ?? 0) + n; 10 counts.set(key, next); 11 return next; 12}); 13 14export const read = mo(import.meta, (key: string): number => { 15 return counts.get(key) ?? 0; 16});