Something went wrong. Try again.
Offload functions to worker threads with shared memory primitives for Node.js.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243import { describe, it } from 'node:test';import assert from 'node:assert/strict';import { mo } from 'moroutine';
describe('AsyncIterableTask', () => { it('mo() with async function* returns AsyncIterableTask', async () => { const { AsyncIterableTask } = await import('../src/stream-task.ts'); const gen = mo(import.meta, async function* () { yield 1; }); const task = gen(); assert.ok(task instanceof AsyncIterableTask); });
it('mo() with regular function still returns PromiseLikeTask', async () => { const { PromiseLikeTask } = await import('../src/task.ts'); const { AsyncIterableTask } = await import('../src/stream-task.ts'); const fn = mo(import.meta, (x: number) => x * 2); const task = fn(2); assert.ok(task instanceof PromiseLikeTask); assert.ok(!(task instanceof AsyncIterableTask)); });
it('AsyncIterableTask has uid, id, and args', async () => { const gen = mo(import.meta, async function* (n: number) { yield n; }); const task = gen(5); assert.equal(typeof task.id, 'string'); assert.deepEqual(task.args, [5]); assert.equal(typeof task.uid, 'number'); });
it('AsyncIterableTask uids are unique', async () => { const gen = mo(import.meta, async function* () { yield 1; }); const a = gen(); const b = gen(); assert.notEqual(a.uid, b.uid); });});