import type { ChildProcess, SpawnOptions } from "node:child_process"; import type { EncodeJob, EncodedImage } from "./image-encode.js"; /** How the host starts and talks to one image worker. */ export interface ImageWorkerOptions { /** Absolute plain Node executable that runs the worker. */ node: string; /** Absolute worker entry path readable by that executable. */ script: string; /** Host environment the worker's own variables are selected from; defaults to process.env. */ environment?: NodeJS.ProcessEnv; /** Process launcher for the worker; defaults to spawn and is injectable for tests. */ launch?: (command: string, args: readonly string[], options: SpawnOptions) => ChildProcess; /** Destination for worker diagnostics; defaults to process.stderr. */ onStderr?: (chunk: string) => void; } /** Run the Sharp encode ladder in a plain Node process. */ export declare class ImageWorker { private child; private pending; private nextId; private writes; private inFlight; private disposed; private readonly node; private readonly script; private readonly environment; private readonly launch; private readonly onStderr; /** @param options - executable, entry, environment, and test seams for the worker. */ constructor(options: ImageWorkerOptions); /** * Encode one image in the worker process. * @param job - source bytes and the ladder knobs the worker needs. * @returns the worker's smallest encoding within the job's budget. * @throws when the request cannot be written, the worker fails, or the reply reports a failure. */ encodeBest(job: EncodeJob): Promise; /** * Stop the worker and resolve only after it has exited. * @returns completion after the process is gone; a worker that ignores the closing * stdin is killed once {@link WORKER_EXIT_TIMEOUT_MS} elapses. */ dispose(): Promise; /** The live worker, started on first use; a worker that died before its exit event is replaced. */ private start; /** Settle the request one reply frame answers, dropping replies that answer nothing. */ private onFrame; /** Reject the one request a failed write belongs to. */ private reject; /** Release this process's event loop once no request is pending. */ private releaseLoop; /** Reject the requests one worker owns, leaving a replacement worker's requests pending. */ private rejectFrom; /** Reject every request, whatever worker owns it. */ private rejectAll; }