0.1.0 • Published 6 years ago

ripeto v0.1.0

Weekly downloads
2
License
GPL-3.0
Repository
github
Last release
6 years ago

ripeto

Runs tasks in a stable repeating loop

Set up

npm install --save ripeto # for npm
yarn add ripeto # for yarn

Usage

const ripeto = require('ripeto');

function doTasks(loopState, errback) {
  // do some things, asynchronously if desired
  doSomeThings((err) => {
    // when complete, invoke the error-first callback
    errback(err);
  });
}

// pass in your own implementation of `doTasks`, and configure the `period`
// which is the duration between successive invocations of `doTasks`
const ripetoInstance = ripeto.impl({ doTasks })({ period: 1000 });

// `doTasks` will be invoked immediately, and then on a regular basis thereafter
ripetoInstance.start();

// `doTasks` will not be invoked any more
ripetoInstance.stop();

Note that ripeto aims to be repeat invocations of doTasks in a stable manner. If doTasks takes a different amount of time to run each time, the subsequent invocation will run at exactly the same interval, unaffected. The exception to this, of course, if doTasks takes longer to complete than the specified interval. In such a scenario, the subsequent invocation will run immediately. This should, however, be avoided by either increasing size of the interval, or more preferably, by splitting doTasks into two independent implementations, and run them using two separate ripeto instances.

Author

Brendan Graetz

Licence

GPL-3.0