@nilestanner/promise-repeat
v1.0.1
Published
repeats promises a number of times or for a time period
Downloads
1
Readme
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