Offload functions to worker threads with shared memory primitives for Node.js.

chore: use overloaded Moroutine type for cleaner IDE signatures

The first overload shows clean parameter types (no Arg<T> wrappers).
The second overload accepts Task<T> args as a fallback. IDEs display
the clean signature by default.

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

+12 -8
+7 -5
src/mo.ts
··· 14 14 15 15 type TaskableArgs<A extends unknown[]> = { [K in keyof A]: Arg<A[K]> }; 16 16 17 - export function mo<A extends unknown[], R>( 18 - importMeta: ImportMeta, 19 - fn: (...args: A) => R, 20 - ): (...args: TaskableArgs<A>) => Task<R> { 17 + type Moroutine<A extends unknown[], R> = { 18 + (...args: A): Task<R>; 19 + (...args: TaskableArgs<A>): Task<R>; 20 + }; 21 + 22 + export function mo<A extends unknown[], R>(importMeta: ImportMeta, fn: (...args: A) => R): Moroutine<A, R> { 21 23 const url = importMeta.url; 22 24 23 25 if (isModuleFrozen(url)) { ··· 33 35 34 36 registry.set(id, fn); 35 37 36 - return ((...args: unknown[]) => new Task<R>(id, args)) as (...args: TaskableArgs<A>) => Task<R>; 38 + return ((...args: unknown[]) => new Task<R>(id, args)) as Moroutine<A, R>; 37 39 }
+2 -2
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, identity, readCtx, addWithCtx } from './fixtures/context.ts'; 4 + import { makeCtx, makeMultiplierCtx, readCtx, addWithCtx } from './fixtures/context.ts'; 5 5 6 6 describe('task-arg caching', () => { 7 7 it('task arg is resolved on the worker', async () => { ··· 44 44 }); 45 45 46 46 it('task arg works alongside regular args', async () => { 47 - const ctx = identity({ multiplier: 3 }); 47 + const ctx = makeMultiplierCtx(3); 48 48 const run = workers(1); 49 49 try { 50 50 const result = await run(addWithCtx(ctx, 2, 5));
+3 -1
test/fixtures/context.ts
··· 7 7 return { value, workerInitId: initCount }; 8 8 }); 9 9 10 - export const identity = mo(import.meta, <T>(value: T): T => value); 10 + export const makeMultiplierCtx = mo(import.meta, (multiplier: number): { multiplier: number } => { 11 + return { multiplier }; 12 + }); 11 13 12 14 export const readCtx = mo( 13 15 import.meta,