UNPKG

retryable-document-client

Version:
27 lines (26 loc) 807 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var defaults_1 = require("./defaults"); ; ; ; ; var factory = function (calculateTimeout, options) { var maxAttempts = (options && options.maxAttempts) || defaults_1.default.maxAttempts; var exceptions = options && options.exceptions; var handleErr = options && options.handleErr; return function (err, attempt, cback) { if (err && (!exceptions || exceptions.includes(err.code)) && (attempt <= maxAttempts)) { var timeout = calculateTimeout(attempt); setTimeout(function () { cback(true); }, timeout); if (handleErr) { handleErr(err); } } else { cback(); } }; }; exports.default = factory;