1 2 3 4 5 6 7 8 9 10 11 12 13 14
export class Scheduler { private timer?: NodeJS.Timeout; public schedule(action: () => void, delay = 0) { this.cancel(); this.timer = global.setTimeout(action, delay); } public cancel() { if (this.timer) { clearTimeout(this.timer); } } }