# co-retry

> Automatically retry generators that fail

Latest version **1.0.5** (published 2015-03-14) · MIT license · 0 weekly downloads

## Install

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

## 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 | 1.0.5 |
| Published | 2015-03-14 |
| First published | 2014-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Manuel Vila |
| Maintainers | mvila |

## Links

- npm: https://www.npmjs.com/package/co-retry
- Repository: https://github.com/mvila/co-retry
- Issues: https://github.com/mvila/co-retry/issues
- npm.io page: https://npm.io/package/co-retry

## Dependencies (1)

- [co-wait](https://npm.io/package/co-wait.md) ^0.0.0

## Recent versions

- 1.0.5 (latest) — 2015-03-14
- 1.0.4 — 2015-01-07
- 1.0.3 — 2015-01-02
- 1.0.2 — 2014-03-21
- 1.0.1 — 2014-03-21
- 1.0.0 — 2014-03-21

## README

# co-retry [![Build Status](https://travis-ci.org/mvila/co-retry.svg?branch=master)](https://travis-ci.org/mvila/co-retry)
Retries generators that throw an error.

## Installation
In your project folder, type:

    npm install co-retry

## Example
Suppose you have a generator function (or any yieldable object constructors supported by [co](https://github.com/visionmedia/co)):

    var job = function *() {
      console.log('Doing something...');
      throw new Error('Failure!!!');
    };

Just wrap that function with co-retry before yielding it.

    var retry = require('co-retry');

    yield retry(job);

## API
### retry(fn, [options])

co-retry will re-run your generator if it throws an error.

    yield retry(job);

If you need to call `fn` with a context and some arguments, simply use the ES5 `bind` feature.

    yield retry(job.bind(ctx, arg1, arg2));

#### Options
The following options are available:

##### retries
The number of times to retry `fn` before giving up and rethrowing the last error caught. *Default: 6.*

    // In case of error, job will be called 1 + 10 times.
    yield retry(job, { retries: 10 });

##### interval
The number of milliseconds to wait between attempts. *Default: 1000.*

##### factor
The factor by which the interval should be multiplied per attempt. If set to 2 with an interval of 5000, the first retry will execute after 5 seconds, the second after 10, the third after 20, and so on. *Default: 2.*

This allows an exponential back-off scheme. For a smaller gap between retries, floats like 1.2 can be used to grow the interval at a slower rate.

## Inspiration
API and documentation heavily inspired from [node-attempt](https://github.com/TomFrost/node-attempt) created by Tom Frost. Thanks to him.

## License
co-retry is distributed under the MIT license.

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