import { 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(worker: WorkerHandle, task: Task): Task { if (task instanceof AsyncIterableTask) { const copy = new AsyncIterableTask(task.id, task.args); copy.worker = worker; return copy as unknown as Task; } const copy = new PromiseLikeTask(task.id, task.args); copy.worker = worker; return copy as unknown as Task; }