···11+import type { Worker } from 'node:worker_threads';
12import type { Task } from './task.ts';
23import type { StreamTask } from './stream-task.ts';
34import type { ChannelOptions } from './channel.ts';
4556type TaskResults<T extends Task<any>[]> = { [K in keyof T]: T[K] extends Task<infer R> ? R : never };
6788+/** A load balancing strategy for choosing which worker runs a task. */
99+export interface Balancer {
1010+ /** Choose a worker for the given task. Called synchronously on every dispatch. */
1111+ select(workers: readonly WorkerHandle[], task: Task<any> | StreamTask<any>): WorkerHandle;
1212+ /** Optional cleanup on sync dispose. */
1313+ [Symbol.dispose]?(): void;
1414+ /** Optional cleanup on async dispose. */
1515+ [Symbol.asyncDispose]?(): Promise<void>;
1616+}
1717+718/** Options for configuring a worker pool. */
819export interface WorkerOptions {
920 /** Maximum time in ms to wait for in-flight tasks during async dispose. If exceeded, workers are force-terminated. */
1021 shutdownTimeout?: number;
2222+ /** Load balancing strategy. Defaults to round-robin. */
2323+ balance?: Balancer;
1124}
12251326/** A handle to a specific worker in a pool. */
···1629 exec<T>(task: Task<T>): Promise<T>;
1730 /** Dispatches a streaming task pinned to this worker. */
1831 exec<T>(task: StreamTask<T>, opts?: ChannelOptions): AsyncIterable<T>;
3232+ /** The underlying worker thread. */
3333+ readonly thread: Worker;
3434+ /** Number of currently in-flight tasks on this worker. */
3535+ readonly activeCount: number;
1936}
20372138/**