1.0.7 • Published 9 years ago

Interval v1.0.7

Weekly downloads
40
License
MIT
Repository
github
Last release
9 years ago

#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');
});