Offload functions to worker threads with shared memory primitives for Node.js.
1import { mo } from '../../src/index.ts';
2
3export const generate = mo(import.meta, async function* (count: number) {
4 for (let i = 1; i <= count; i++) {
5 yield i;
6 }
7});
8
9export const double = mo(import.meta, async function* (input: AsyncIterable<number>) {
10 for await (const n of input) {
11 yield n * 2;
12 }
13});
14
15export const square = mo(import.meta, async function* (input: AsyncIterable<number>) {
16 for await (const n of input) {
17 yield n * n;
18 }
19});
20
21export const toString = mo(import.meta, async function* (input: AsyncIterable<number>) {
22 for await (const n of input) {
23 yield `=> ${n}`;
24 }
25});