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 85db7bc257c01f3eed5be11f13ce5e363c575d2e 27 lines 690 B view raw
1import type { Task } from './runner.ts'; 2 3type TaskOf<M> = M extends { (...args: any[]): infer R } 4 ? R extends Task<infer T, infer A> 5 ? Task<T, A> 6 : never 7 : never; 8 9/** 10 * Narrows a task to the descriptor type produced by a specific moroutine. 11 * 12 * ```ts 13 * if (isTask(isPrime, task)) { 14 * // task: Task<boolean, [n: number]> 15 * } 16 * ``` 17 * 18 * @param moroutine - A function returned by {@link mo}. 19 * @param task - A task to test. 20 * @returns `true` if `task` was created by `moroutine`. 21 */ 22export function isTask<M extends { readonly id: string; (...args: any[]): Task<any, any> }>( 23 moroutine: M, 24 task: Task, 25): task is TaskOf<M> { 26 return task.id === moroutine.id; 27}