# retry-times

> retry a task at most given times

Latest version **3.0.1** (published 2018-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install retry-times
pnpm add retry-times
yarn add retry-times
bun add retry-times
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2018-04-27 |
| First published | 2017-11-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | zhaoyao91 |
| Maintainers | zhaoyao91 |
| Keywords | retry |

## Links

- npm: https://www.npmjs.com/package/retry-times
- Repository: https://github.com/zhaoyao91/retry-times
- Homepage: https://github.com/zhaoyao91/retry-times#readme
- Issues: https://github.com/zhaoyao91/retry-times/issues
- npm.io page: https://npm.io/package/retry-times

## Recent versions

- 3.0.1 (latest) — 2018-04-27
- 3.0.0 — 2018-01-12
- 2.0.0 — 2017-12-25
- 1.0.0 — 2017-11-10

## README

# Retry Times

> Retry a task at most given times.

## Deprecation

**This package is deprecated to prefer the new [retry-func](https://github.com/zhaoyao91/retry-func) package.**

## Installation

```
npm i retry-times --save
```

## Usage

### Retry a task directly

```ecmascript 6
const {buildRetry} = require('retry-times')

// a task is any function without argument
const task = async () => {
  ...
}

const retry = buildRetry(3) // or buildRetry({times: 3})
const data = await retry(task)
```

### Wrap a task with retry

```ecmascript 6
const {buildWithRetry} = require('retry-times')

// a task is any function without argument
const task = async () => {
  ...
}

const withRetry = buildWithRetry(3) // or buildWithRetry({times: 3})
const taskWithRetry = withRetry(task)
const data = taskWithRetry()
```


## API

### buildRetry

`buildRetry(options) => retry(task) => Promise`

### buildWithRetry

`buildWithRetry(options) => withRetry(task) => wrappedTask() => Promise`

### options

- times - the task will run at most times
- onRetry - `onRetry(err, runCount)`, callback when the task is about to retry 

The relations of run, onRetry, and runCount are as below:

```
run           ->             run           ->             run...
    onRetry(err, runCount=1)     onRetry(err, runCount=2)
```

## License

MIT

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