UNPKG

@toreda/time

Version:

Simple, small footprint library for common time operations and converting between units of time.

46 lines (45 loc) 1.56 kB
import type { Bool, Float } from '@toreda/strong-types'; import type { Time } from '../time'; import { Timer } from '../timer'; import { TimerCallback } from './callback'; import { TimerCallbackGroup } from './callback/group'; import { TimerCallbackSync } from './callback/sync'; import type { TimerEventId } from './event/id'; import type { TimerOptions } from './options'; /** * Active timer with internal timing clock. Takes a callback to invoke * every timer trigger. * * @category Timers */ export declare class TimerActive { private _timerHandle; private readonly _checkIntervalMs; readonly _handlersBound: Bool; readonly lastIntervalEnd: Float; readonly limitDuration: Bool; readonly listeners: Record<TimerEventId, TimerCallbackGroup>; readonly paused: Bool; readonly running: Bool; readonly timeLimit: Time; readonly timeStart: Time; readonly timeStop: Time; constructor(options?: TimerOptions); getListenerGroup(id: TimerEventId): TimerCallbackGroup | null; on(id: TimerEventId, fn: TimerCallback | TimerCallbackSync): boolean; once(id: TimerEventId, fn: Timer | TimerCallbackSync): boolean; setTimeLimit(value: number | Time): boolean; bindHandlers(): void; unpause(): Promise<boolean>; pause(): Promise<boolean>; /** * Start the timer. * @returns */ start(): Promise<boolean>; done(): Promise<boolean>; stop(): Promise<boolean>; executeCallbacks(eventId: TimerEventId): Promise<void>; reset(): void; onUpdate(): void; }