delay-repeater

1.0.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i delay-repeater

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

4.91 kB

Total Files

8

Last publish

Collaborators

  • xavierchow