import type { ApiFailure, ApiResult } from './importApi.js'; /** How often the page asks while something is going on (§ 8.2). */ export declare const POLL_INTERVAL_MS = 5000; /** The longest the page waits between two asks when the server pushes back. */ export declare const MAX_BACKOFF_MS = 30000; /** * The longest wait the page accepts from `Retry-After`. Core's limit counts a * minute (`base/services/rateLimit.ts`), so a longer wait is a mistake of a proxy. */ export declare const MAX_RETRY_AFTER_MS = 60000; /** The browser, as the poller sees it: a timer and the visibility of the tab. */ export interface PollerEnvironment { /** The time, in milliseconds since 1970. */ now(): number; setTimer(run: () => void, ms: number): unknown; clearTimer(handle: unknown): void; isVisible(): boolean; /** Calls `listener` when the tab is shown or hidden; returns the way to stop. */ onVisibilityChange(listener: () => void): () => void; } export interface PollerOptions { env: PollerEnvironment; /** One ask. It never throws: a failure is a result. */ fetch(): Promise>; /** Whether to go on asking after this answer. */ keepGoing(value: T): boolean; /** Every answer that is a success, in order. */ onValue(value: T): void; /** What the page does with an answer that is not one (it keeps its last state). */ onFailure?(failure: ApiFailure, willRetryInMs: number | null): void; intervalMs?: number; } /** * Asks for a value every few seconds while `keepGoing` says so and the tab is * visible (§ 8.2). It never has two asks in the air, and it asks again after the * last one ended (not on a fixed clock, so a slow server is not piled on). When * the server answers 429 or fails, the page keeps its last state and waits: * as long as `Retry-After` says, otherwise twice the last wait, up to 30 seconds; * the first good answer brings the normal rhythm back. */ export declare class Poller { private readonly options; private readonly interval; private timer; private inFlight; private stopped; private generation; private wait; private last; private unsubscribe; constructor(options: PollerOptions); /** * Begins, with the value that is already known: nothing is asked while it says * the job is over. Without one, the first ask is made at once. */ start(known?: T): void; /** Asks now, for example after the admin pressed a button. */ refresh(): void; stop(): void; private cancelTimer; private schedule; private visibilityChanged; private ask; private answered; }