1.1.1 • Published 5 years ago

@hattmo/tryagain v1.1.1

Weekly downloads
-
License
GPL-3.0-or-later
Repository
-
Last release
5 years ago

TRYAGAIN

About

Retrys code that can throw an exception N number of times.

How to

import tryagain from "../src/index";

// Returns a promise that resolves to the return from the body function.
// Will reject when the body function fails N times and throw the most recent error.
// Calling exit will escape the attemps early and throw the most recent error
// If a promise is returned in either the body or the error handler, it will wait until the Promise is resolved before continuing.
tryagain(5, (attempt) => {

    // Will run 5 times before actually throwing
    potentialThrowingFunction("Bad Input");

    if (attempt > 2) { // Contains the current attempt number
        trysomethingelse("Good Input");
    }
}, (error, attempt, exit) => {
    console.log(`Attempt number ${attempt} had the following error: ${error}`);
});

Author

Designed and maintained by Matthew Howard.

Support me with a donation!

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago