interface IWorkerOptions { numWorkers?: number; env?: Record; silent?: boolean; } type WrapReturnOfAFunctionInAPromise) => any> = (...a: Parameters) => Promise>; type EnsureFunctionReturnsAPromise = MaybeFunction extends (...args: Array) => Promise ? MaybeFunction : MaybeFunction extends (...args: Array) => any ? WrapReturnOfAFunctionInAPromise : never; type WrapReturnInArray = MaybeFunction extends (...args: Array) => any ? (...a: Parameters) => Array> : never; export type CreateWorkerPoolType = WorkerPool & { [FunctionName in keyof ExposedFunctions]: EnsureFunctionReturnsAPromise; } & { all: { [FunctionName in keyof ExposedFunctions]: WrapReturnInArray>; }; }; export interface IPublicWorkerInfo { workerId: number; } /** * Worker pool is a class that allow you to queue function execution across multiple * child processes, in order to parallelize work. It accepts absolute path to worker module * and will expose exported function of that module as properties on WorkerPool instance. * * Worker pool allows queueing execution of a function on all workers (via `.all` property) * as well as distributing execution across workers (via `.single` property) */ export declare class WorkerPool, MessagesFromParent = unknown, MessagesFromChild = MessagesFromParent> { private workerPath; private options?; /** * Schedule task execution on all workers. Useful for setting up workers */ all: { [FunctionName in keyof WorkerModuleExports]: WrapReturnInArray>; }; /** * Schedule task execution on single worker. Useful to distribute tasks between multiple workers. */ single: { [FunctionName in keyof WorkerModuleExports]: EnsureFunctionReturnsAPromise; }; private workers; private taskQueue; private idleWorkers; private listeners; private counter; constructor(workerPath: string, options?: IWorkerOptions | undefined); private startAll; /** * Kills worker processes and rejects and ongoing or pending tasks. * @returns Array of promises for each worker that will resolve once worker did exit. */ end(): Array>; /** * Kills all running worker processes and spawns a new pool of processes */ restart(): Promise; getWorkerInfo(): Array; private checkForWork; private doWork; private scheduleWork; private scheduleWorkSingle; private scheduleWorkAll; onMessage(listener: (msg: MessagesFromChild, workerId: number) => void): void; sendMessage(msg: MessagesFromParent, workerId: number): void; } export * from "./child";