# @collectai/node-retry

> Retry library

Latest version **0.4.0** (published 2021-07-19) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @collectai/node-retry
pnpm add @collectai/node-retry
yarn add @collectai/node-retry
bun add @collectai/node-retry
```

## 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.4.0 |
| Published | 2021-07-19 |
| First published | 2017-06-20 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 18.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | collectai |

## Links

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

## Dependencies (1)

- [backoff](https://npm.io/package/backoff.md) ^2.5.0

## Recent versions

- 0.4.0 (latest) — 2021-07-19
- 0.3.0 — 2018-04-09
- 0.2.1 — 2018-03-01
- 0.2.0 — 2017-06-28
- 0.1.2 — 2017-06-21
- 0.1.1 — 2017-06-21
- 0.1.0 — 2017-06-20

## README

# node-retry

## Install

`npm install @collectai/node-retry`

## Quickstart

```javascript
var nodeRetry = require('@collectai/node-retry')();

var count = 0;
nodeRetry(function(cb) {
  console.log('myfunc called ' + (++count) + ' times');
  if (count < 3) {
    var error = new Error('Service connection error');
    error.code = 'ETIMEDOUT';
    cb(error);
  } else {
    cb(null, 'succeed the third time');
  }
}).then(function(result) {
  console.log(result);
});
```

### Configurable retry validation

```javascript
var nodeRetry = require('@collectai/node-retry')({
  retryIf: function(error) {
    // Custom error validation to retry
    return error.message === 'DB connection error';
  }
});

var count = 0;
nodeRetry(function(cb) {
  console.log('myfunc called ' + (++count) + ' times');
  if (count < 3) {
    cb(new Error('DB connection error'));
  } else {
    cb(null, 'succeed the third time');
  }
}).then(function(result) {
  console.log(result);
});
```

### Promise retry

```javascript
var nodeRetry = require('@collectai/node-retry')();

var count = 0;
nodeRetry()(function() {
  console.log('myfunc called ' + (++count) + ' times');
  return new Promise(function(resolve, reject) {
    if (count < 3) {
      var error = new Error('Service connection error');
      error.code = 'ETIMEDOUT';
      reject(error);
    } else {
      resolve('succeed the third time');
    }
  });
}).then(function(result) {
  console.log(result);
});
```

All these examples will display:

```
myfunc called 1 times
myfunc called 2 times
myfunc called 3 times
succeed the third time
```

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