Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/parzh/retryable
Convenience function which helps to retry an action
https://github.com/parzh/retryable
delayed promise retry retry-executing wait
Last synced: 1 day ago
JSON representation
Convenience function which helps to retry an action
- Host: GitHub
- URL: https://github.com/parzh/retryable
- Owner: parzh
- Created: 2020-01-28T15:57:52.000Z (almost 5 years ago)
- Default Branch: develop
- Last Pushed: 2023-10-17T04:08:45.000Z (over 1 year ago)
- Last Synced: 2025-01-10T04:55:23.543Z (16 days ago)
- Topics: delayed, promise, retry, retry-executing, wait
- Language: TypeScript
- Homepage: https://npmjs.org/package/@parzh/retryable
- Size: 822 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `@parzh/retryable`
Convenience function to retry executing an action, until a desired result is achieved
## Installation
```
npm i @parzh/retryable
``````
yarn add @parzh/retryable
```## Usage
```js
const content = await retryable((resolve, reject, retry) => {
fs.readfile("/path/to/file", (err, data) => {
if (!err)
// no errors occured
return resolve(data);// here: an error occured
if (retry.count >= RETRY_LIMIT)
if (SHOULD_IGNORE_RETRY_LIMIT)
// retry limit reached, but ignored
retry.setCount(0);else
// retry limit reached
return reject("Retry limit reached!");// here: retry limit is ignored or not reached
if (SHOULD_RETRY_IMMEDIATELY)
// retrying immediately
retry();else
// retrying after exponential backoff (see https://en.wikipedia.org/wiki/Exponential_backoff)
retry.after("exponential"); // same as: retry.after(2 ** retry.count * 100);
});
});
```