/** * Copyright (c) 2017-present A. Matías Quezada */ import AnimationTimer from './animation-timer'; import BaseTimer, { TimerCallback } from './base-timer'; /** * Creates an object to control delayed time execution. You only need to provide * the callback to invoke and the milliseconds to wait once. * After that you can schedule, cancel and reschedule the timer as many times * as you need to. */ export default class Timer extends BaseTimer { /** * Returns a promise to be fulfilled after `milliseconds` milliseconds. * * @param milliseconds {Number} Milliseconds to wait until the promise is resolved. * @param callback {Function?} Optional function to invoke when the timer is over. */ static timeout(milliseconds: number): Promise; static timeout(milliseconds: number, callback: TimerCallback): Promise; /** * Creates and returns a timer scheduled to invoke the callback every * `milliseconds` milliseconds. * * @param milliseconds {Number} Milliseconds to wait between callback executions. * @param callback {Function} Function to invoke on each iteration. */ static interval(milliseconds: number, callback: TimerCallback): Timer; /** * Creates and returns a timer which will use `requestAnimationFrame` to * invoke the callback. * * @param callback {Function} Function to invoke on each frame. */ static animation(callback: TimerCallback): AnimationTimer; protected _setTimer(): number; protected _clearTimer(): void; }