Interval

1.0.7 • Public • Published

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

Dependents (3)

Package Sidebar

Install

npm i Interval

Weekly Downloads

2

Version

1.0.7

License

MIT

Last publish

Collaborators

  • scottliu2011