export declare enum IntervalState { IDLE = 0, RUNNING = 1, PAUSED = 2, RESUME = 3 } /** * `IntervalTimer` is a class that handles logic for intervals, e.g. start stop, reset, resume, pause & maximum amount of fires. */ export default class IntervalTimer { /** * Called after every interval. */ callback: () => void; /** * Time between intervals, in milliseconds. */ interval: number; /** * Maximum amount of fires. */ maxFires?: number | undefined; /** * The state to handle logic. * - 0 means the interval is idle. * - 1 means it's running. * - 2 means it's paused * - 3 will resume. */ state: IntervalState; /** * Remaining time before the next interval. */ remaining: number; /** * Amount of times fired. */ fires: number; /** * Time passed after pausing, */ pausedTime: number | Date; private lastTimeFired?; private timerId?; private resumeId?; private lastPauseTime?; private constructor(); /** * Handles the callback execution, the amount of fires, & the times when fired. * If `this.maxFires` is **not** null, and it's bigger than `this.fires` and if `this.fires` exists, meaning if it the interval was at least started once before, then never fire again. */ private intervalHandler; /** * `timeoutHandler` is executed by `resume`. `timeoutHandler` is the callback of a new `setTimeout` executed by `resume` to mimic a resume function. * The callback is executed by running `intervalHandler`, and then `start` is executed to run a new interval. */ private timeoutHandler; /** * `start` executes the interval, and saves the interval ID for further use. * The time of execution is also fired in case it's paused later on. The state * is finally set as running. */ start: () => void; /** * `stop` clears every respective timeout and interval, then sets the state as idle. */ stop: () => void; /** * Resets the interval. */ reset: () => void; /** * `pause` tries to mimic pausing the interval by calculating the remaining time and storing it * in a member variable. Afterwards clear the respective timeout and interval then set the new * state. */ pause: () => void; /** * `resume` calculates the remaining time for the callback to trigger using the values * set by `paused`. Will execute a new `setTimeout` while passing the `remaining` time * as the timeout delay. */ resume: () => void; /** * Set a new interval to use on the next interval loop. */ setInterval: (newInterval: number) => void; /** * Maximum amount of times the `callback` member will execute, it's infinite by default. */ setMaxFires: (newMax: number) => void; private static instance; static new(callback: () => void, interval: number, maxFires?: number | undefined): IntervalTimer; } //# sourceMappingURL=IntervalTimer.d.ts.map