Negatory. Postpone Mission.

    @nilestanner/promise-repeat

    1.0.1 • Public • Published

    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

    Keywords

    none

    Install

    npm i @nilestanner/promise-repeat

    DownloadsWeekly Downloads

    2

    Version

    1.0.1

    License

    ISC

    Last publish

    Collaborators

    • nilestanner