UNPKG

@tempest/core

Version:

The core of the Tempest Stream Library

38 lines 763 B
import { defer } from '../util/task'; export class ClockTimer { now() { return Date.now(); } setTimer(fn, delayTime) { return delayTime <= 0 ? runAsTask(fn) : setTimeout(fn, delayTime); } clearTimer(task) { return task instanceof Asap ? task.dispose() : clearTimeout(task); } } export class Asap { constructor(f) { this.f = f; this.active = true; } run(time) { if (this.active) this.f(); } error(time, e) { throw e; } dispose() { this.active = false; } } function runAsTask(f) { const task = new Asap(f); defer(task); return task; } //# sourceMappingURL=ClockTimer.js.map