/** * Clock abstraction for deterministic testing. * FakeClock allows complete control over time in tests. * RealClock is a passthrough to native timers (for production). */ /** * Clock interface: abstracts setTimeout, setInterval, Date.now(). * Used by features like heartbeat, limits, and test utilities. */ export interface Clock { /** * Schedule a function to run after delay (milliseconds). * Returns a timer ID that can be passed to clearTimeout. */ setTimeout(fn: () => void, ms: number): unknown; /** * Clear a scheduled timeout. */ clearTimeout(id: unknown): void; /** * Schedule a function to repeat every interval (milliseconds). * Returns a timer ID that can be passed to clearInterval. */ setInterval(fn: () => void, ms: number): unknown; /** * Clear a scheduled interval. */ clearInterval(id: unknown): void; /** * Current time in milliseconds since epoch (or fake clock start). */ now(): number; } /** * Fake clock for deterministic testing. * Supports full control over time progression and task scheduling. * * Usage: * const clock = new FakeClock(); * await clock.tick(30_000); // Advance time 30s and run due timers * await clock.flush(); // Flush microtasks without advancing time */ export declare class FakeClock implements Clock { private now_; private timers; private nextId; private queue; /** * Get current fake time. */ now(): number; setTimeout(fn: () => void, ms: number): unknown; clearTimeout(id: unknown): void; setInterval(fn: () => void, ms: number): unknown; clearInterval(id: unknown): void; /** * Advance time by ms milliseconds and run all due timers. * Flushes microtasks between timer runs. * Repeats until no more timers are due. */ tick(ms: number): Promise; /** * Flush pending microtasks without advancing time. * Useful after inbound messages to settle promise chains. */ flush(): Promise; /** * Reset clock: clear all timers and set time to 0. */ reset(): void; /** * Get list of pending timers (for debugging/leak detection). */ pendingTimers(): { id: unknown; dueAt: number; isInterval: boolean; }[]; private enqueueTimer; private runDueTimers; } /** * System clock: passthrough to native timers. * Use for production or when you don't need deterministic testing. */ export declare class SystemClock implements Clock { setTimeout(fn: () => void, ms: number): unknown; clearTimeout(id: unknown): void; setInterval(fn: () => void, ms: number): unknown; clearInterval(id: unknown): void; now(): number; } //# sourceMappingURL=fake-clock.d.ts.map