https://github.com/audienseco/retry-backoff
Handle callback retries with incremental backoff and timeout support.
https://github.com/audienseco/retry-backoff
backoff callback retry timeout
Last synced: about 1 year ago
JSON representation
Handle callback retries with incremental backoff and timeout support.
- Host: GitHub
- URL: https://github.com/audienseco/retry-backoff
- Owner: AudienseCo
- License: mit
- Created: 2016-06-13T14:18:40.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2019-09-08T08:08:49.000Z (over 6 years ago)
- Last Synced: 2025-03-13T21:17:16.163Z (about 1 year ago)
- Topics: backoff, callback, retry, timeout
- Language: JavaScript
- Homepage:
- Size: 47.9 KB
- Stars: 0
- Watchers: 12
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# retry-backoff

[](https://travis-ci.org/AudienseCo/retry-backoff)
[](https://david-dm.org/AudienseCo/retry-backoff)
[](https://david-dm.org/AudienseCo/retry-backoff#info=devDependencies)
[](https://www.npmjs.org/package/retry-backoff)
[](https://paypal.me/AudienseCo)
> Handle callback retries with incremental backoff and timeout support.
## Install
```bash
$ npm install retry-backoff --save
```
## Usage
```js
const createRetryBackoff = require('retry-backoff')
function fn (cb) {
setTimeout(function () {
return cb(null, {foo: 'bar'})
}, 1000)
}
const retryBackoff = createRetryBackoff()
retryBackoff(fn, function (err, result) {
if (err) throw err
retryBackoff.reset()
console.log(result) // => {foo: 'bar'}
})
```
If you need to see low level logs, enable it using `DEBUG=retry-backoff`.
## API
### retryBackoff([options])
Creates a backoff function.
#### options
##### timeout
Type: `number`
Default: `30000`
Setup the time (in milliseconds) after consider a request timeout.
##### retries
Type: `number`
Default: `3`
Number of retries before throw a final error.
##### backoff
Type: `function`
Default: `1000 * Math.pow(2, retry) + Math.random() * 100`
The method uses for calculate the incremental delay between sucesive calls, where `retry` is attempt number (starts from 0).
### .reset
Restart the `retries` counter.
## License
MIT © [AudienseCo](https://audiense.com/)