export type TimerController = { clear: () => void; }; export type TimerMap = Record; export declare const MAX_DELAY_MS = 2147483647; /** * @internal A drop-in replacement for `setTimeout` that supports arbitrarily long delays. * * ### Why? * Browsers clamp `setTimeout` delays to a 32-bit signed integer, * i.e. a maximum of ~24.8 days (`2_147_483_647ms`). Any larger value * will fire almost immediately. This helper safely schedules timeouts * that can be months or years into the future. * * ### How it works * - On call, we record a fixed **target timestamp** (`now + delayMs`). * - We schedule a single "leg" of at most ~24.8 days into the future, * with an internal `tick` function as the callback. * - When a leg expires, `tick` checks how much time is left: * - If `remaining > 0`, it schedules the next leg (`min(MAX_DELAY_MS, remaining)`). * - If `remaining <= 0`, the full delay has passed and we finally call your `cb()`. * - At any time, only **one** leg is active. Calling `.clear()` cancels * the current leg and prevents further hops. * * ### Benefits * - Works seamlessly for both short and very long delays. * - Survives tab sleep / system suspend: when the tab wakes, * `tick` re-checks the target timestamp and fires immediately if overdue. * - No drift accumulation: each hop recalculates based on the fixed target, * so you always land as close as possible to the intended deadline. * * ### Example * ```ts * const controller = setCappedTimeout(() => { * console.log("A whole year later!"); * }, 1000 * 60 * 60 * 24 * 365); * * // Cancel if needed * controller.clear(); * ``` * * @param cb - Function to run once the full delay has elapsed. * @param delayMs - Delay in milliseconds (can exceed 2_147_483_647). * @returns A controller with a `.clear()` method to cancel the timeout. */ export declare function setCappedTimeout(cb: () => void, delayMs: number): TimerController; /** @internal Simple one-shot timeout that still returns a controller for uniformity. */ export declare function setTimeoutController(cb: () => void, delayMs: number): TimerController; /** @internal Replace any existing timer for `key` with `controller`. */ export declare function putTimer(map: TimerMap, key: string, controller: TimerController): void; /** @internal Clear a specific key (noop if missing). */ export declare function clearKey(map: TimerMap, key: string): void; /** @internal Clear several keys at once (noop on missing). */ export declare function clearKeys(map: TimerMap, keys: string[]): void; /** @internal Clear all timers in the map. */ export declare function clearAll(map: TimerMap): void; /** * @internal Convenience: set a capped timeout directly into the map for `key`. * @param map The map to store the timer in (pass in the ref to the timer map) * @param key The key to associate with the timer * @param cb The callback to invoke when the timer expires * @param delayMs The delay in milliseconds before the timer expires * */ export declare function setCappedTimeoutInMap(map: TimerMap, key: string, cb: () => void, delayMs: number): void; /** * @internal Convenience: set a regular (short) timeout into the map for `key`. * @param map The map to store the timer in (pass in the ref to the timer map) * @param key The key to associate with the timer * @param cb The callback to invoke when the timer expires * @param delayMs The delay in milliseconds before the timer expires */ export declare function setTimeoutInMap(map: TimerMap, key: string, cb: () => void, delayMs: number): void; //# sourceMappingURL=timers.d.ts.map