# promise-chain-retry

> when promise chain has error, some time we need to retry

Latest version **1.1.1** (published 2022-07-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install promise-chain-retry
pnpm add promise-chain-retry
yarn add promise-chain-retry
bun add promise-chain-retry
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2022-07-28 |
| First published | 2022-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | kangjs |
| Maintainers | kangjs7854 |
| Keywords | promise, chain, retry |

## Links

- npm: https://www.npmjs.com/package/promise-chain-retry
- Repository: https://github.com/kangjs7854/promise-chain-retry
- npm.io page: https://npm.io/package/promise-chain-retry

## 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

- 1.1.1 (latest) — 2022-07-28
- 1.0.9 — 2022-07-28
- 1.0.7 — 2022-07-28
- 1.0.0 — 2022-07-28

## README

# why we need to retry promise?

when promise chain has error, some time we need to retry

```js
function api(){
    const id1 = await genId1();
    console.log(id1)
    const id2 = await genId2(id1);
    return id2
}

//first call, genId2 throw error
api() //123

//retry, genId2 normal, but gen aother id1
api() //666


```

# use promise-chain-retry

```js
import { promiseChainInit } from 'promise-chain-retry'

const chain = promiseChainInit();

function api() {
  chain.next(async () => {
    return await genId1();
  });
  chain.next(async (id1) => {
    console.log(id1);
    return await genId2(id1);
  });

  return chain.execute();
}

//first call, genId2 throw error
api(); //123

//retry, genId2 normal, reused successful promises
api(); //123
```

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