import { Disposable } from "../../../base/common/lifecycle.js"; import { ILogService } from "../../log/common/log.service.js"; import { IRequestScheduler } from "./scheduler.js"; /** * Shapes how far apart repeated attempts against a failing subject are spaced. * Without one, every subscriber that reacts to a failure retries at its normal * rate for the whole outage, which turns one unhealthy dependency into a * request storm against the service from every user at once. */ export interface BackoffPolicy { /** Consecutive failures that may retry without waiting, so a single blip still recovers at once. */ readonly immediateRetries: number; readonly base: number; readonly maximum: number; readonly jitter: number; /** * Quiet time after which consecutive failures are forgotten. Only * {@link BackoffGate} consults it, for subjects whose recovery nothing * else can report; callers that observe a success reset the count directly. */ readonly decay?: number; } /** * The delay an attempt must serve after `attempts` consecutive failures, never * shorter than `minimum`. Jittered so a host that fails many callers at once * does not gather them into a single retry burst when the delay elapses. */ export declare function backoffDelay(policy: BackoffPolicy, scheduler: IRequestScheduler, attempts: number, minimum?: number): number; /** * Holds back attempts against a single subject that keeps failing, spacing them * further apart the longer the trouble lasts. * * Callers wait rather than being rejected, so recovery stays automatic and * everyone queued behind one delay shares the single attempt that follows it. * The subject is named by an opaque key -- which may carry a secret and is * therefore never logged -- so replacing it recovers immediately. */ export declare class BackoffGate extends Disposable { private readonly _label; private readonly _policy; private readonly _scheduler; private readonly _logService?; private readonly _lifetime; private _changed; private _state; constructor(_label: string, _policy: BackoffPolicy, _scheduler: IRequestScheduler, _logService?: ILogService | undefined); /** * Waits until an attempt for `key` may run and reports whether it had to. * A key this gate holds no failure for proceeds at once. */ wait(key: string, signal: AbortSignal): Promise; /** Records a failure for `key`, respecting any server-required minimum delay. */ fail(key: string, minimumDelay?: number): void; /** Forgets the recorded failures, releasing anyone already waiting. */ reset(): void; dispose(): void; /** Replaces the record and wakes every caller waiting on the previous one. */ private _set; }