/** * Copyright (c) 2017-present A. Matías Quezada */ export default abstract class BaseTimer { protected readonly milliseconds: number; protected readonly callback: TimerCallback; protected _domId: number; protected _isLooping: boolean; /** * Creates a new timer. * * @param milliseconds {Number} The milliseconds until the callback will be invoked. * @param callback {Function} The callback to invoke. */ constructor(milliseconds: number, callback: TimerCallback); /** * Will schedule the timer to invoke the callback once after `milliseconds`. * * @returns {Promise|Boolean} False if the timer was already set. True if the timer successfully started. */ schedule(): boolean; /** * Will cancel next executions of this timer. * This will prevent the callback to be invoked again until the timer is * scheduled or started again. * * @returns {Boolean} False if the timer was not running. True if the timer successfully stopped. */ cancel(): boolean; /** * It will ensure the timer will reset and start the delay again from 0. * If the timer is not running it will schedule it. */ reschedule(): void; /** * It will start the timer as a repetitive timer. * The callback will be called every `milliseconds` milliseconds until it's stopped. * * @returns {Boolean} False if the timer was already set. True if the timer successfully started. */ start(): boolean; /** * This will prevent the callback to be invoked again until the timer is * scheduled or started again. * * @returns {Boolean} False if the timer was not running. True if the timer successfully stopped. */ stop(): boolean; /** * It will ensure the timer will reset and start the delay again from 0. * If the timer is not running it will schedule it. */ restart(): void; protected abstract _setTimer(): number; protected abstract _clearTimer(): void; protected _tick(delay: number): void; } export declare type TimerCallback = (delay: number) => T;