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.

test: rewrite nested task-arg test to actually test nesting

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

+12 -6
+8 -6
test/context.test.ts
··· 1 1 import { describe, it } from 'node:test'; 2 2 import assert from 'node:assert/strict'; 3 3 import { workers } from 'moroutine'; 4 - import { makeCtx, makeMultiplierCtx, readCtx, addWithCtx } from './fixtures/context.ts'; 4 + import { makeCtx, makeMultiplierCtx, readCtx, addWithCtx, prefixValue } from './fixtures/context.ts'; 5 5 6 6 describe('task-arg caching', () => { 7 7 it('task arg is resolved on the worker', async () => { ··· 54 54 } 55 55 }); 56 56 57 - it('moroutine task arg resolves and caches', async () => { 58 - const ctx = makeCtx('nested'); 57 + it('nested task args resolve recursively', async () => { 58 + // makeCtx('hello') is a task-arg passed to prefixValue 59 + // prefixValue itself is the outer task dispatched to the worker 60 + // The worker must resolve makeCtx first, then call prefixValue with the result 61 + const ctx = makeCtx('hello'); 59 62 const run = workers(1); 60 63 try { 61 - const result = await run(readCtx(ctx)); 62 - assert.equal(result.value, 'nested'); 63 - assert.equal(typeof result.workerInitId, 'number'); 64 + const result = await run(prefixValue(ctx, '>>> ')); 65 + assert.equal(result, '>>> hello'); 64 66 } finally { 65 67 run[Symbol.dispose](); 66 68 }
+4
test/fixtures/context.ts
··· 21 21 export const addWithCtx = mo(import.meta, (ctx: { multiplier: number }, a: number, b: number): number => { 22 22 return (a + b) * ctx.multiplier; 23 23 }); 24 + 25 + export const prefixValue = mo(import.meta, (ctx: { value: string; workerInitId: number }, prefix: string): string => { 26 + return prefix + ctx.value; 27 + });