1.0.1 • Published 6 years ago

@nilestanner/promise-repeat v1.0.1

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

Promise Repeater

Ever need to repeat a backend call? Or try something until it works? Well promise reapeater is here to repeat your promises.

Installation

$ npm install @nilestanner/promise-repeat --save

Usage

import {repeatPromise} from 'path/to/node_modules';

or

var repeatPromise = require('path/to/node_modules');

Simple example

Just pass a function that returns a valid promise and repeatPromise will repeat the function 3 times by default.

function returnsPromise(){
    return new Promise (...);
}

repeatPromise(returnsPromise).then(...);

A more complex example

You may also pass in a object with some options for more control. In this example there are two end conditions. If repeatPromise runs for 3 seconds or runs 10 times it will resolve the promise.

function returnsPromise(){
    return new Promise (...);
}

var options = {
  attempts:10,
  timeLimit:3000
};
repeatPromise(returnsPromise,options).then(...);

Demo

Coming soon

1.0.1

6 years ago

1.0.0

6 years ago