export class Timer {
    constructor(callback, timeMs) {
        this.pause = () => {
            clearTimeout(this.id);
            this.id = undefined;
            this.timeRemaining = (this.finishTime || 0) - Date.now();
        };
        this.resume = () => {
            this.id = setTimeout(this.finish, this.timeRemaining);
            this.finishTime = Date.now() + (this.timeRemaining || 0);
            this.timeRemaining = undefined;
        };
        this.clear = () => {
            clearTimeout(this.id);
            this.id = undefined;
            this.callback = undefined;
            this.finishTime = undefined;
            this.timeRemaining = undefined;
        };
        this.finish = () => {
            if (this.callback) {
                this.callback();
            }
            this.clear();
        };
        this.id = setTimeout(this.finish, timeMs);
        this.callback = callback;
        this.finishTime = Date.now() + timeMs;
        this.timeRemaining = undefined;
    }
}
//# sourceMappingURL=timer.js.map