UNPKG

timers3000

Version:

Provides a graphical interface in your browser to create and manage incremental timers for your daily tasks.

27 lines (20 loc) 559 B
var SleepTime = function(thresh, wakeUpCallback){ this.thresh = thresh; this.wakeUpCallback = wakeUpCallback; this.lastTick; this.start(); } SleepTime.prototype.start = function() { var self = this; self.lastTick = Date.now(); setInterval(function () { self.tick();}, (self.thresh/3)); }; SleepTime.prototype.tick = function() { var self = this; var diff = Date.now() - self.lastTick; if(diff > self.thresh){ self.wakeUpCallback(diff); } self.lastTick = Date.now(); }; module.exports = SleepTime;