import { Thread } from "./thread"; /** Pool event type. Specifies the type of each `PoolEvent`. */ export declare enum PoolEventType { initialized = "initialized", taskCanceled = "taskCanceled", taskCompleted = "taskCompleted", taskFailed = "taskFailed", taskQueued = "taskQueued", taskQueueDrained = "taskQueueDrained", taskStart = "taskStart", terminated = "terminated" } export declare type TaskRunFunction = (worker: ThreadType) => Promise; /** Pool event. Subscribe to those events using `pool.events()`. Useful for debugging. */ export declare type PoolEvent = { type: PoolEventType.initialized; size: number; } | { type: PoolEventType.taskQueued; taskID: number; } | { type: PoolEventType.taskQueueDrained; } | { type: PoolEventType.taskStart; taskID: number; workerID: number; } | { type: PoolEventType.taskCompleted; returnValue: any; taskID: number; workerID: number; } | { type: PoolEventType.taskFailed; error: Error; taskID: number; workerID: number; } | { type: PoolEventType.taskCanceled; taskID: number; } | { type: PoolEventType.terminated; remainingQueue: Array>; }; export interface WorkerDescriptor { init: Promise; runningTasks: Array>; } /** * Task that has been `pool.queued()`-ed. */ export interface QueuedTask { /** @private */ id: number; /** @private */ run: TaskRunFunction; /** * Queued tasks can be cancelled until the pool starts running them on a worker thread. */ cancel(): void; /** * `QueuedTask` is thenable, so you can `await` it. * Resolves when the task has successfully been executed. Rejects if the task fails. */ then: Promise["then"]; }