delay-repeater
v1.0.2
Published
Run a function repeatly with a delay
Downloads
4
Readme
Run your code repeatly with a delay
Install
npm install delay-repeater
Usage
//es6 module
import repeat from 'delay-repeater';
//or CommonJS require style
const repeat = require('delay-repeater').default;
const fn = () => {
console.log('ipsum');
}
const times = 3;
const interval = 3000; // 3 seconds
repeat(fn, times, interval);
//or with an error first callback
const done = (e) => {
if (e) {
return console.log(e);
}
console.log('3 times execution finished');
}
repeat(fn, times, interval, done);
Note If the fn
returns a Promise, the delay will be after the Promise resolved, this is easy to run some asynchrous codes(e.g. http request or IO) repeatly.
License
MIT