# redo-promise

> Retry a promise, when async function call.

Latest version **0.0.1** (published 2018-08-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install redo-promise
pnpm add redo-promise
yarn add redo-promise
bun add redo-promise
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2018-08-27 |
| First published | 2018-08-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | hustcc |
| Maintainers | atool |
| Keywords | retry, retry-promise, redo-promise, retry-async |

## Links

- npm: https://www.npmjs.com/package/redo-promise
- Repository: https://github.com/hustcc/redo-promise
- Homepage: https://github.com/hustcc/redo-promise#readme
- Issues: https://github.com/hustcc/redo-promise/issues
- npm.io page: https://npm.io/package/redo-promise

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.0.1 (latest) — 2018-08-27

## README

# redo-promise

> Retry a promise, when async function call. 异步 Promise 函数重试机制。

[![Build Status](https://travis-ci.org/hustcc/redo-promise.svg?branch=master)](https://travis-ci.org/hustcc/redo-promise)
[![Coverage Status](https://coveralls.io/repos/github/hustcc/redo-promise/badge.svg?branch=master)](https://coveralls.io/github/hustcc/redo-promise)
[![npm](https://img.shields.io/npm/v/redo-promise.svg)](https://www.npmjs.com/package/redo-promise)
[![npm](https://img.shields.io/npm/dm/redo-promise.svg)](https://www.npmjs.com/package/redo-promise)



# Install

Install By:

> npm i --save redo-promise

Then import it by:

```js
import retry from 'redo-promise';
```



# Usage

You can create `retry` by the API provided by `redo-promise`. It has 3 parameters:

 - `promiseFn`: the target promise function.
 - `predicate`: function decided whether should be retry.
 - `opts`: retry strategy.


```js
import retry from 'redo-promise';

const fetchUser = id => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({ id: 'hustcc', name: 'hustcc' });
    }, 10);
  });
};

const fn = retry(fetchUser, r => r.success);

// if the request result is not success, it will retry 5 times.
fn('hustcc').then(user => {}).catch(e => {});
```


You can customize the retry `opts`.

```js
import retry from 'redo-promise';

const fn = retry(fetchUser, r => r.success, { delay: 3000, max: 3 });

// if the request result is not success, it will retry 3 times per 3 seconds.
fn('hustcc').then(user => {}).catch(e => {});
```

`opts` contains:

 - `delay`: retry delay time in `ms`, default `1000`.
 - `max`: max retry count, default `5`.



# License

ISC@[hustcc](https://github.com/hustcc).

---
_Source: https://npm.io/package/redo-promise · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
