https://github.com/codewell/retry-js
Recursively retries a function if it fails
https://github.com/codewell/retry-js
Last synced: 9 months ago
JSON representation
Recursively retries a function if it fails
- Host: GitHub
- URL: https://github.com/codewell/retry-js
- Owner: codewell
- License: mit
- Created: 2020-04-17T10:12:06.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T03:47:05.000Z (over 3 years ago)
- Last Synced: 2025-02-22T07:31:49.999Z (over 1 year ago)
- Language: JavaScript
- Size: 997 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @codewell/retry
Recursively retries to call a function if the execution fails.
## Installation
```
npm install @codewell/retry
```
## Basic Usage
```JavaScript
import retry from '@codewell/retry';
retry(fetch)("http://example.com")
.then(data => {
// Do something with the returned data,
// in this case an http response,
// from fetch("http://example.com")
})
.catch(error => {
// This is where we end up if all retries
// failed to execute
});
```
`retry` will make the function call `fetch("http://example.com")`. If it fails, `retry` will try to call `fetch("http://example.com")` for 3 times (default) before it gives up.
### Configuration
`retry` is also configurable with options:
```JavaScript
import retry from '@codewell/retry';
const options = {
// Number of tries before we stop
// Default value: 3
maxTries: 3,
// A function that returns number
// of milliseconds to wait before
// next execution
// Default function: (retryCount) => 1000
backoffStrategy: (retryCount) => 1000,
// Parameter from 0-2 that sets
// how much logging retry should do.
// Default value: 1
logLevel: 1,
};
retry(fetch, options)("http://example.com");
```
The `options` object is optional to pass. All options are optional to configure.
## Contribution
Please help by submitting issues and pull requests here on github
Read more on [codewell's webpage](https://codewell.github.io/contribution)