UNPKG

maestro

Version:

Maestro is a framework for quickly bootstrapping serverless orchestration workflows with AWS Step Functions

30 lines (25 loc) 512 B
const sleep = require("./sleep"); const retryAsync = async ( promiseCallback, maxAttempts = 3, interval = 2000, backoffRate = 3 ) => { try { await promiseCallback(); } catch (err) { // base case if (maxAttempts <= 1) { throw err; } console.log("Unsuccessful operation. Retrying..."); await sleep(interval); await retryAsync( promiseCallback, maxAttempts - 1, interval * backoffRate, backoffRate ); } }; module.exports = retryAsync;