# retry-function-promise

> "Nothing yet"

Latest version **1.0.2** (published 2018-02-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install retry-function-promise
pnpm add retry-function-promise
yarn add retry-function-promise
bun add retry-function-promise
```

## 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.2 |
| Published | 2018-02-07 |
| First published | 2018-02-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Adomas Griskelis |
| Maintainers | adomas000 |
| Keywords | github.com/adomas000/retry-function-promise |

## Links

- npm: https://www.npmjs.com/package/retry-function-promise
- npm.io page: https://npm.io/package/retry-function-promise

## Alternatives

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

## Recent versions

- 1.0.2 (latest) — 2018-02-07
- 1.0.1 — 2018-02-07
- 1.0.0 — 2018-02-06

## README

# retry-function-promise

## Get module

```js
var retryFunctionPromise = require("retry-function-promise");
```
## Parameters to retryFunctionPromise(count, interval, function, args)

* #count    - how many times to retry 
* #interval - how much time to wait between retries
* #function - function you want to execute or Array [this, function] if nested/inner e.g. A.B.C() -> [A.B, A.B.C()];
* #args     - arguments to pass to function you want to execute number of times

###### In the future will probably add overloading

## Simple function example
```js
var cnt = 0;
//function you wish to repeat until it doesnt throw error
function regularFunction(arg1, arg2){
    cnt++;
    if(cnt==3) return true;
    else throw "Error";
}

retryFunctionPromise(5, 500, regularFunction, ["firstArgument",{second:"argument"}])
    .then((success)=>{
        console.log("Function completed execution without any errors");
    })
    .catch((error)=>{
        console.error("All tries were unsuccesfull: " + error);
    })
```
## Also works with promises

```js
var cnt = 0;
function promiseFunction(arg1, arg2){
    return new Promise((resolve, reject)=>{
        cnt++;
        if(cnt==3) resolve();
        else reject("Error");

    })
    
}

retryFunctionPromise(5, 500, promiseFunction, ["firstArgument",{second:"argument"}])
    .then((success)=>{
        console.log("Function completed execution without any errors");
    })
    .catch((error)=>{
        console.error("All tries were unsuccesfull: " + error);
    })

```
## Nested functions

```js
var cnt = 0;
first = {
    second:{
        third: function (){
            cnt++;
            if(cnt==4) return true;
            else throw "ERROR";
        }
    }
};
//first.second acts as "this", when calling -> first.second.third.call(first.second, arguments);
retryFunctionPromise(5, 500, [first.second, first.second.third], [])
    .then((success)=>{
        console.log("Function completed execution without any errors");
    })
    .catch((error)=>{
        console.error("All tries were unsuccesfull: " + error);
    })
```

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