Interval
v1.0.7
Published
A lightweight Interval runner as an alternative of setInterval()
Downloads
8
Maintainers
Readme
#A lightweight Interval runner as an alternative of setInterval()
##Usage
var Interval = require('Interval');
var count = 0;
// create an Interval runner
var runner = Interval.run(function() {
console.log(++count);
}, 1000);
// pause when satisfying the specified condition
runner.pauseWhen(function() {
return count % 10 == 0;
}, 1000);
// do something when paused
runner.whenPaused(function() {
console.log('paused');
});
// keep running until the specified condition
runner.until(function() {
return count == 100;
});
// do something when runner stopped
runner.end(function() {
console.log('stopped');
});
// it also support the function chain:
Interval.run(function() {
console.log(++count);
}, 1000).pauseWhen(function() {
return count % 10 == 0;
}, 500).whenPaused(function() {
console.log('paused');
}).until(function() {
return count == 100;
}).end(function() {
console.log('stopped');
});