cfn-response-async
Version:
An async/await module for sending responses from lambda-funciton backed custom resources in AWS CloudFormation
33 lines • 963 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var defaultOptions = {
retries: 3,
delay: 500,
count: 0
};
/**
* Use the setTimeout to delay retry
*/
var delay = function (options) {
return new Promise(function (resolve) { return setTimeout(resolve, options.delay * options.count); });
};
/**
* This run the lib
* Receive the promiseFn
*/
exports.retry = function (requestFn, options) {
if (options === void 0) { options = defaultOptions; }
// const optionsParsed = buildOptionsParsed(options);
// const { onRetry, shouldRetry } = optionsParsed;
var promise = requestFn();
return promise.catch(function (err) {
if (options.count++ < options.retries) {
return delay(options).then(function () {
return exports.retry(requestFn, options);
});
}
throw err;
});
};
exports.default = exports.retry;
//# sourceMappingURL=retry.js.map