class AbstractIntervalWorker { start(interval) { var self = this; self.stop(); self.timer = setInterval(async () => { if (self.ticking) return; self.ticking = true; try { await self.tick(); } catch (err) { console.log(err); } self.ticking = false; }, interval); } stop() { var self = this; if (self.timer) { clearInterval(self.timer); self.timer = null; } } /* Implement this: async tick() { } */ } module.exports = AbstractIntervalWorker;