Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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);
});
});
```