Repeat function with async
npm install async-repeat- About
- Install
- Usage
- Contribute
- Testing
- License
Repeat function with async.
``shell`
npm install async-repeat
`javascript
// 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
},
);
})();
`
``
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. |
Clone the repository and execute:
```
npm test
MIT.