UNPKG

@pryv/monitor

Version:

Extends `pryv` with event-driven notifications for changes on a Pryv.io account

29 lines (25 loc) 772 B
/** * @license * [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE) */ const UpdateMethod = require('./UpdateMethod'); class EventsTimer extends UpdateMethod { /** * @param {Number} updateRateMS - the refresh rate in milliseconds */ constructor (updateRateMS) { super(); this.timer = null; if (!updateRateMS || isNaN(updateRateMS) || updateRateMS < 1) { throw new Error('Monitor timer refresh rate is not valid. It should be a number > 1'); } this.updateRateMS = updateRateMS; } async ready () { if (this.timer != null) clearTimeout(this.timer); this.timer = setTimeout(() => { if (this.monitor.started) this.monitor.updateEvents(); }, this.updateRateMS); } } module.exports = EventsTimer;