https://github.com/nassiharel/backoff.js
Fibonacci, exponential and fixed backoffs for Node.js.
https://github.com/nassiharel/backoff.js
backoff fibonacci retry strategy
Last synced: 11 months ago
JSON representation
Fibonacci, exponential and fixed backoffs for Node.js.
- Host: GitHub
- URL: https://github.com/nassiharel/backoff.js
- Owner: nassiharel
- Created: 2017-10-31T15:56:45.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T17:49:42.000Z (over 3 years ago)
- Last Synced: 2025-06-24T18:18:31.703Z (12 months ago)
- Topics: backoff, fibonacci, retry, strategy
- Language: JavaScript
- Size: 364 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Backoff for Node.js
Fibonacci, exponential, fixed and linear backoffs for Node.js.
## Installation
$ npm install backoff.js
## Features
* Fibonacci and exponential backoffs for Node.js.
* Runs promise/callback/sync functions
## Viewing Examples
```js
const backoff = require('backoff.js');
const backoff = new Backoff({
strategy: 'fixed', // fixed/expo/fibo/linear
delay: 100, // in ms
maxAttempts: 3
});
backoff.on('retry', (error, data) => {
console.log(`retry -> strategy: ${data.strategy}, attempt: ${data.attempt}, delay: ${data.delay}, error: ${error.message}`);
});
backoff.on('failed', (error) => {
console.log(`retry -> error: ${error.message}`);
});
// if your function is callback style, convert it to promise.
// e.g. util.promisify(func)
backoff.run(promiseFunction, { data: 'test' }).then(() => {
console.log(`success`);
}).catch((err) => {
console.log(`failed`);
});
```
## Running Tests
npm test
## License
This code is free to use under the terms of the [MIT license](http://mturcotte.mit-license.org/).