npm.io
0.0.3 • Published 7 years ago

async-repeat

Licence
MIT
Version
0.0.3
Deps
0
Size
140 kB
Vulns
0
Weekly
0

async repeat

Table of Contents

About

Repeat function with async.

Install

npm install async-repeat

Usage

// CommonJS
// const axiosRetry = require('async-repeat');

// ES6
import asyncRepeat from "async-repeat";

(async () => {
  await asyncRepeat(
    async done => {
      try {
        const res = await rp("http://www.google.com");
        done();
      } catch (e) {
        // Do nothing, repeat.
      }
    },
    {
      delay: 1000, // default 3000
      maxCount: 5, // default 10
    },
  );
})();
API
asyncRepeat(retrier: Function, options: Object) => Promise
Retrier
  • The supplied function receives two parameters:
    • done: Resolve repeat function.
    • utils: Utilities for repeat function.
      • utils.checkCount: Repeat count.
      • utils.reject: Reject the repeat function.
      • utils.resovle: Resolve the repeat function, it same done.
Options
Name Type Default Description
delay number 3000 Repeat interval (ms).
maxCount number 10 Maximum repeat times.
defaultResult any null Return value when the maximum number of times is exceeded.

Testing

Clone the repository and execute:

npm test

Contribute

Open an issue or submit PRs.

License

MIT.