/// import { EventEmitter } from 'events'; export interface Timer extends EventEmitter { updateTimeout(timeout: number): void; cancel(): void; } export declare class FakeTimer extends EventEmitter implements Timer { cancel: () => void; updates: number[]; constructor(cancel?: () => void); updateTimeout(t: number): void; } export interface Options { clock?: () => number; setTimeout?: (cb: () => void, t: number) => number; clearTimeout?: (t: number) => void; } /** * TimeoutTimer is a class that sets a timer similarly to setTimeout. The * difference is that TimeoutTimer also supports changing the timeout while * it's running. This is used for test timeouts; the tests can change their * own timeout while they are run. (Yes, this is a bit crazy, but I want to * be mocha compatible.) * * TimeoutTimer is an EventEmitter and will emit a 'timeout' message when the * time is up. * * @param timeout The timeout in milliseconds * @param options For testing purposes and other customization, it's possible * to inject non-standard means of measuring time and setting timeouts. * { * clock: [function that returns the current time as a Date object], * setTimeout: [set a timeout. Same signature as Javascript's setTimeout. * Rhis function should always invoke its callback asynchronously], * clearTimeout: [cancel a timeout. Same signature as Javascript's clearTimeout] * } * Optional. */ export default class TimeoutTimer extends EventEmitter implements Timer { #private; private timeout; constructor(timeout: number, { clock, ...opts }?: Options); private timedOut; /** * Calculate the remaining time for this timeout. May return a negative number. */ private remainingTime; private armTimeout; /** * Change the timeout of this object. The timeout is relative from when the * timer was created. Setting the timeout to a time that has already passed * causes the timer to elapse immediately (on the next tick). */ updateTimeout(timeout: number): void; /** * Cancel the timer. */ cancel(): void; }