# ritry

> ## Install ``` $ npm install --save ritry ```

Latest version **0.1.0** (published 2019-05-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install ritry
pnpm add ritry
yarn add ritry
bun add ritry
```

## Health

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

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

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2019-05-14 |
| First published | 2019-05-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 172.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | highhi |
| Maintainers | highhi |
| Keywords | promise, retry, retry promise |

## Links

- npm: https://www.npmjs.com/package/ritry
- Repository: https://github.com/highhi/ritry
- Issues: https://github.com/highhi/ritry/issues
- npm.io page: https://npm.io/package/ritry

## 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.1.0 (latest) — 2019-05-14
- 0.0.4 — 2019-05-12
- 0.0.3 — 2019-05-11
- 0.0.2 — 2019-05-11
- 0.0.1 — 2019-05-11

## README

# ritry

## Install
```
$ npm install --save ritry
```

## Usage
The following code throws an error after 4 retries.

``` javascript
import { ritry } from 'ritry'

function promiseFunction() {
  return new Promise((_, reject) => {
    setTimeout(() => reject(new Error('fail')), 500)
  })
}

ritry(promiseFunction, { retry: 4 }).catch((err) => {
  console.error(err)
})
```

you can gradually increase the duration.

``` javascript
import { ritry } from 'ritry'

function promiseFunction({ retryCount }) {
  const duration = 1000 + retryCount * 200
  return new Promise((_, reject) => {
    setTimeout(() => reject(new Error('fail')), duration)
  })
}

ritry(promiseFunction, { retry: 4 }).catch((err) => {
  console.error(err)
})
```

```
declare type Callback<T> = () => Promise<T>;
declare type Options = {
  retry?: number;
};
export declare function ritry<T>(callback: Callback<T>, options?: Options): Promise<T>;
```


## Options
### retry
`default: 1`  
You can change the number of retries


## License
MIT

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