UNPKG

igir

Version:

🕹 A zero-setup ROM collection manager that sorts, filters, extracts or archives, patches, and reports on collections of any size on any OS.

42 lines • 1.05 kB
import { clearTimeout } from 'node:timers'; /** * A wrapper to centrally manage Node.js timeouts. */ class Timer { constructor(timeoutId) { this.timeoutId = timeoutId; Timer.TIMERS.add(this); } static setTimeout(runnable, timeoutMillis) { const timer = new Timer(setTimeout(() => { runnable(); Timer.TIMERS.delete(timer); }, timeoutMillis)); return timer; } static setInterval(runnable, timeoutMillis) { const timer = new Timer(setInterval(() => { runnable(); Timer.TIMERS.delete(timer); }, timeoutMillis)); return timer; } /** * Cancel all pending timeouts. */ static cancelAll() { Timer.TIMERS.forEach((timer) => { timer.cancel(); }); } /** * Cancel this timeout. */ cancel() { clearTimeout(this.timeoutId); Timer.TIMERS.delete(this); } } Timer.TIMERS = new Set(); export default Timer; //# sourceMappingURL=timer.js.map