try-to

0.0.1 • Public • Published

try-to

Try to do a task, try again if it fails, backing-off with a customisable algorithm, and returning a promise.

npm install try-to --save

Usage

A simple example, illustrating all of the main API features.

'use strict';
const tryto = require('try-to');
 
tryto(function() {
    // Do stuff, throw on failure, or return result...
    // Can return a promise, which will be waited on
})  .every(100)                 // start retrying at 100ms intervals
    .for(20)                    // max 20 retries
    .using(tryto.exponential)   // exponential back-off
    .config({ max: 1e6 })       // cap it to 1,000s retries
    .now()                      // start trying immediately
    .then(result => {
        // Function got ran!
    }, err => {
        // Function didn't successfully run
    });

API Docs

For complete API docs see API.md.

Package Sidebar

Install

npm i try-to

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • jonhall