# promise-to-retry

> Helper function to easily retry some action returning Promise until it succeeds

Latest version **2.5.1** (published 2018-08-09) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install promise-to-retry
pnpm add promise-to-retry
yarn add promise-to-retry
bun add promise-to-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 | 2.5.1 |
| Published | 2018-08-09 |
| First published | 2018-08-09 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Martynas |
| Maintainers | mkazlauskas |
| Keywords | retry, promise |

## Links

- npm: https://www.npmjs.com/package/promise-to-retry
- Homepage: https://github.com/firmfirm/promise-to-retry/
- npm.io page: https://npm.io/package/promise-to-retry

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@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

## Recent versions

- 2.5.1 (latest) — 2018-08-09

## README

# PromiseToRetry [ ![Codeship Status for firmfirm/promise-to-retry](https://codeship.com/projects/c3d88730-bd0d-0133-cfbe-129a4e5cf2b4/status?branch=master)](https://codeship.com/projects/136432)

Utility functions that helps dealing with Javascript Promises.

  - `ensure(fn => Promise, cb)` is a helper function to retry some action returning Promise until it succeeds.
  - `setTimeoutToPromise(fn => Promise, wait)` waits for specified amount of time before invoking your function. Resolves with promise resulting from provided fn.
  - `new Queue().queue(fn => Promise)` invokes functions one by one (waits for firstly enqueued functions to resolve their results)

Usage:

`bower install --save promise-to-retry`

```html
<link rel="import" href="bower_components/promise-to-retry/promise-to-retry.html">
```

```javascript
PromiseToRetry.ensure(function() {
  // return your promise that might fail,
  // etc. instead of this it could do Promise.reject
  return Promise.resolve('ensured');
})
.then(function(result) {
  console.log(result); // 'ensured'
})
.catch(function(error) {
  // this can never happen
});

PromiseToRetry.setTimeoutToPromise(function() {
  // this is delayed by 1000ms
  return Promise.resolve('delayed');
}, 1000)
.then(function(result)) {
  console.log(result); // 'delayed'
}
.catch(function(error) {
  // this can still happen
});

var queue = new PromiseToRetry.Queue();
var first = queue.queue(() => new Promise(...));
queue.queue(() => {
  // this will not get called until first promise resolves
  return Promise.resolve('second');
});
```

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