rtimer
Persistent timer with set and clear
Install
npm install rtimer
Usage
rtimer has two instance methods set
and clear
.
set
restart the timeoutclear
clear the current timeout, timeout can be restarted again after clearcallback
property contains the callback methoddelay
property contains the timeout delay
Example
var rtimer = require('rtimer');
var start_time = +new Date();
var timeout = rtimer(function() {
var t = (+new Date() - start_time);
console.log('time ' + t + ' ms');
timeout.delay = 500;
timeout.callback = function() {
console.log('Hello World!');
};
timeout.set();
}, 1000);
setTimeout(function() {
timeout.set();
}, 500);