# promise-retryer

> provides an easy way to make promises retry based on exceptions or result validation

Latest version **0.0.1** (published 2015-01-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install promise-retryer
pnpm add promise-retryer
yarn add promise-retryer
bun add promise-retryer
```

## 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.0.1 |
| Published | 2015-01-05 |
| First published | 2015-01-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 20 |
| Author | Chad Scira |
| Maintainers | icodeforlove |

## Links

- npm: https://www.npmjs.com/package/promise-retryer
- Repository: https://github.com/icodeforlove/promise-retryer
- Issues: https://github.com/icodeforlove/promise-retryer/issues
- npm.io page: https://npm.io/package/promise-retryer

## Dependencies (1)

- [promise-object](https://npm.io/package/promise-object.md) ^0.1.4

## Recent versions

- 0.0.1 (latest) — 2015-01-05
- 0.0.0 — 2015-01-04

## README

# promise-retryer [![Build Status](https://travis-ci.org/icodeforlove/promise-retryer.png?branch=master)](https://travis-ci.org/icodeforlove/promise-retryer)

provides an easy way to make promises retry based on exceptions or result validation

## install

```
npm install promise-retryer
```

## params

- delay (can be a number or function that returns a number, if its a function it gets called with an attempt argument)
- maxRetries (the maximum amount of retries)
- validate (validation promise) 
- onError (callback function on errors, gets called with an error object and an attempt argument)
- onAttempt (callback function on attempts, gets called with an attempt argument)
- debug (enable verbose logging)
- name (this is useful for debugging purposes)

## examples

heres a basic retry example

```javascript
var PromiseRetryer = require('promise-retryer')(Promise);

PromiseRetryer.run({
	delay: 1000,
	maxRetries: 5,
	promise: function (attempt) {
		return makeAsyncRequest(); // returns a promise
	}
}).then(
	function (response) {
		console.log(response);
	},
	function (error) {
		console.log(error);
	}
);
```

and heres a little more advanced example with validation and custom delays

```javascript
var PromiseRetryer = require('promise-retryer')(Promise);

PromiseRetryer.run({
	delay: function (attempt) {
		return attempt * 1000;
	},
	maxRetries: 5,
	promise: function (attempt) {
		return makeAsyncRequest(); // returns a promise
	},
	validate: function (response, attempt) {
		return new Promise(function (resolve, reject) {
			if (typeof response === 'object') {
				resolve(response);
			} else {
				reject(new Error('response was not an object'));
			}
		});
	}
}).then(
	function (response) {
		console.log(response);
	},
	function (error) {
		console.log(error);
	}
);
```

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