Something went wrong. Try again.
Offload functions to worker threads with shared memory primitives for Node.js.
Something went wrong. Try again.
12345678910111213141516171819202122import { PromiseLikeTask } from './task.ts';import { AsyncIterableTask } from './stream-task.ts';import type { Task, WorkerHandle } from './runner.ts';
/** * Returns a copy of the task pinned to a specific worker. * The original task is unchanged. * @param worker - The worker handle to pin the task to. * @param task - The task to assign. * @returns A new task with the same id and args, pinned to the given worker. */export function assign<T>(worker: WorkerHandle, task: Task<T>): Task<T> { if (task instanceof AsyncIterableTask) { const copy = new AsyncIterableTask(task.id, task.args); copy.worker = worker; return copy as unknown as Task<T>; } const copy = new PromiseLikeTask(task.id, task.args); copy.worker = worker; return copy as unknown as Task<T>;}