import { type SendHandle } from 'node:child_process';
import EventEmitter from 'node:events';
/**
 * Central registry of message type names, which are used to identify
 * the payload in {@link Message} objects sent between processes. The
 * payloads themselves are implementation specific and defined in each
 * component; only the type name is reserved here to avoid collisions.
 *
 * Receiving logic can call {@link getMessage()} with the name of
 * the message of interest to filter messages to those of interest.
 */
export declare const MESSAGE_TYPES: {
    readonly handoff: "handoff";
    readonly status: "status";
    readonly subscribe: "subscribe";
    readonly notify: "notify";
    readonly ready: "ready";
};
export type Message<Payload> = [keyof typeof MESSAGE_TYPES, Payload];
export interface Sender {
    send<M extends Message<unknown>>(message: M, sendHandle?: SendHandle, callback?: (error: Error | null) => void): boolean;
    kill(signal?: NodeJS.Signals): void;
}
export interface Subprocess extends Sender, EventEmitter {
    pid?: number | undefined;
}
export interface Receiver extends EventEmitter {
    /**
     * The receiving side of {@link Sender.send()} that is a wrapper around
     * {@link on}('message', ...) that invokes the `handler` for messages of
     * the specified `type`.
     */
    onMessageType<M extends Message<unknown>>(type: M[0], handler: (msg: M[1], sendHandle?: SendHandle) => void): this;
    /**
     * The receiving side of {@link Sender.send()} that behaves like
     * {@link once}('message', ...) that invokes the `handler` for the next
     * message of the specified `type` and then unsubscribes.
     */
    onceMessageType<M extends Message<unknown>>(type: M[0], handler: (msg: M[1], sendHandle?: SendHandle) => void): this;
}
export interface Worker extends Subprocess, Receiver {
}
/**
 * The parentWorker for forked processes, or `null` if the process was not forked.
 * (Analogous to the `parentPort: MessagePort | null` of the `"workers"` library).
 */
export declare const parentWorker: Worker | null;
export declare function singleProcessMode(): boolean;
export declare function setSingleProcessMode(enabled?: boolean): void;
/**
 *
 * @param modulePath Path to the module file, relative to zero-cache/src/
 */
export declare function childWorker(modulePath: string, env?: NodeJS.ProcessEnv | undefined, ...args: string[]): Worker;
/**
 * Creates two connected `Worker` instances such that messages sent to one
 * via the {@link Worker.send()} method are received by the other's
 * `on('message', ...)` handler.
 *
 * This is analogous to the two `MessagePort`s of a `MessageChannel`, and
 * is useful for executing code written for inter-process communication
 * in a single process.
 */
export declare function inProcChannel(): [Worker, Worker];
//# sourceMappingURL=processes.d.ts.map