import type { Counter, Distribution, Metrics } from "crow-metrics"; import { PersistentQueue, QueuedJob, QueuedQueryJob } from "./persistent_queue"; import { PromiseCallbacks } from "./promises"; import { Timer } from "./timer"; export declare function delay(msec: number): Promise; export interface WorkerPoolOptions { workerConfig: Object; localHandler?: (job: J) => J | null; logger?: (text: string) => void; errorLogger?: (error: Error | undefined, text: string) => void; traceLogger?: (text: string) => void; notifyError?: (error: WorkerPoolError) => void; metrics?: Metrics; describeJob: (job: J) => string; pingFrequency: number; pingTimeout: number; replyTimeout: number; workerDeathThreshold: number; workerDeathDuration: number; } export declare const DEFAULT_WORKER_POOL_OPTIONS: WorkerPoolOptions; export declare enum WorkerPoolError { WORKER_DIED = 1,// we'll restart it WORKER_TIMED_OUT = 2,// we'll restart it WORKER_POOL_DIED = 3 } export declare const WORKER_POOL_ERROR_DESCRIPTIONS: Map; export declare class WorkerStatus

{ id: number; status: P | string; constructor(id: number, status: P | string); } export interface Ready { type: "ready"; } export interface PostJob { type: "post"; job?: J; jobs?: J[]; } export interface TimerJob { type: "timer"; timeout: number; job: J; } export interface ExpiresJob { type: "expires"; expires: number; job: J; } export interface JobDone { type: "done"; success: boolean; pong?: boolean; errorMessage?: string; reply?: J; } export interface Reply { type: "reply"; returnAddress: string; reply: J; } export interface Status

{ type: "status"; time: number; errorMessage?: string; reply?: P; } export type WorkerMessage = Ready | PostJob | JobDone | Reply | TimerJob | ExpiresJob | Status

; export declare class WorkerPool { queue: PersistentQueue; timer: Timer; options: WorkerPoolOptions; private workerCodePath; private workers; private idleWorkers; protected stopping: boolean; private nextId; protected replies: Map>; jobCounter?: Counter; jobTiming?: Distribution; pingDistribution?: Distribution; deadCounter?: Counter; private pingsWaiting; private pingTimer; private pingTimeoutTimer; private workerDeathCount; private workerDeathSince; private monitorTime; private monitorResults; constructor(queue: PersistentQueue, timer: Timer, options?: Partial>); launch(workerCodePath: string, count: number): void; ready(count: number): Promise; idle(): Promise; stop(): Promise; stopped(): boolean; add(job: J): QueuedJob; addQuery(job: J): QueuedQueryJob; monitor(frequency: number, timeout: number): AsyncIterable[]>; private launchWorker; private dropWorker; private workerFinished; workerReply(returnAddress: string, reply: J): void; private gotPong; private startNextJob; private ping; checkAbandonedPromises(): void; private logPingResults; private log; private logError; private logTrace; } export declare class FakeWorkerPool extends WorkerPool { queue: PersistentQueue; timer: Timer; processJob: (job: J, returnAddress?: string) => Promise; currentJob: Promise; _idle: boolean; constructor(queue: PersistentQueue, timer: Timer, options: Partial> | undefined, processJob: (job: J, returnAddress?: string) => Promise); launch(_workerCodePath: string, _count: number): void; ready(count: number): Promise; idle(): Promise; stop(): Promise; }