import type { CircuitBreakerConfig, CircuitEntry, CircuitState } from './circuit-breaker.js'; /** * Shared circuit state for `CircuitBreaker`, loaded only when a `store` is configured. * * Kept out of the breaker's own module so that a per-process breaker — the default, and the right * choice for one process — does not carry the code that coordinates several. */ /** @internal What the coordinator needs from the breaker it serves. */ export interface CircuitHost { readonly config: CircuitBreakerConfig; readonly workerId: string; now(): number; entry(providerName: string): CircuitEntry; names(): Iterable; transition(providerName: string, entry: CircuitEntry, to: CircuitState, reason: string, options?: { openedAt?: number; publish?: boolean; }): void; refresh(providerName: string, entry: CircuitEntry): void; } /** @internal */ export declare class CircuitCoordinator { private readonly host; private readonly pending; private syncing; private lastSyncAt; /** False after a store failure, until a sync succeeds; the breaker then decides locally. */ private reachable; constructor(host: CircuitHost); /** * Whether this worker may go half-open once a cooldown has elapsed. With a reachable store only * the worker holding the probe may; the rest stay open until that probe settles it for everyone. */ mayProbe(entry: CircuitEntry): boolean; /** Starts a background sync when the last one is older than the interval. Never waits. */ tick(): void; sync(): Promise; /** Publishes a transition this worker made. */ published(providerName: string, entry: CircuitEntry, to: 'open' | 'closed', reason: string): void; /** Publishes an operator reset, so every worker closes the circuit rather than only this one. */ reset(names: Iterable): void; /** * Publishes anything that opened before this module finished loading, then starts the first sync. * The load takes one turn of the event loop; a circuit opened inside it must not stay local. */ reconcile(): void; flush(): Promise; /** Takes a decision another worker published, when it is newer than what this worker knows. */ private adopt; /** * A timestamp strictly after the last transition this worker knew of. Two transitions inside one * millisecond would otherwise tie, and "newest wins" cannot order a tie. */ private stampAfter; private publish; private failed; }