import { LogContext } from '@rocicorp/logger';
import { sleepWithAbort } from '../../../shared/src/sleep.ts';
export declare const DEFAULT_MAX_RETRY_DELAY_MS = 10000;
export type RetryConfig = {
    initialRetryDelay?: number;
    maxRetryDelay?: number;
};
export interface Cancelable {
    cancel(): void;
}
export type UnregisterFn = () => void;
/**
 * Facilitates lifecycle control with exponential backoff.
 */
export declare class RunningState {
    #private;
    constructor(serviceName: string, retryConfig?: RetryConfig, setTimeoutFn?: typeof setTimeout, sleeper?: typeof sleepWithAbort);
    /**
     * Returns `true` until {@link stop()} has been called.
     *
     * This is usually called as part of the service's main loop
     * conditional to determine if the next iteration should execute.
     */
    shouldRun(): boolean;
    /**
     * Registers a Cancelable object to be invoked when {@link stop()} is called.
     * Returns a method to unregister the object.
     */
    cancelOnStop(c: Cancelable): UnregisterFn;
    /**
     * Sets a Timeout that is automatically cancelled if the service is cancelled.
     */
    setTimeout<TArgs extends unknown[]>(fn: (...args: TArgs) => void, timeoutMs: number, ...args: TArgs): void;
    /**
     * Returns a promise that resolves after `ms` milliseconds or when
     * the service is stopped.
     */
    sleep(ms: number): Promise<void>;
    /**
     * Called to stop the service. After this is called, {@link shouldRun()}
     * will return `false` and the {@link stopped()} Promise will be resolved.
     */
    stop(lc: LogContext, err?: unknown): void;
    /**
     * Returns a Promise that resolves when {@link stop()} is called.
     */
    stopped(): Promise<void>;
    /**
     * Call in response to an error or unexpected termination in the main
     * loop of the service. The returned Promise will resolve after an
     * exponential delay, or once {@link stop()} is called.
     *
     * If the supplied `err` is an `AbortError`, the service will shut down.
     */
    backoff(lc: LogContext, err: unknown): Promise<void>;
    /**
     * When using {@link backoff()}, this method should be called when the
     * implementation receives a healthy signal (e.g. a successful
     * response). This resets the delay used in {@link backoff()}.
     */
    resetBackoff(): void;
}
/**
 * Superclass for Errors that should bypass exponential backoff
 * and immediately shut down the server.
 */
export declare class UnrecoverableError extends Error {
    readonly name = "UnrecoverableError";
}
//# sourceMappingURL=running-state.d.ts.map