PHP 8.2.30
Preview: retry.js Size: 5.39 KB
/home/byroehnu/easepay.easetack.com/node_modules/async/retry.js

'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.default = retry;

var _wrapAsync = require('./internal/wrapAsync.js');

var _wrapAsync2 = _interopRequireDefault(_wrapAsync);

var _promiseCallback = require('./internal/promiseCallback.js');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function constant(value) {
    return function () {
        return value;
    };
}

/**
 * Attempts to get a successful response from `task` no more than `times` times
 * before returning an error. If the task is successful, the `callback` will be
 * passed the result of the successful task. If all attempts fail, the callback
 * will be passed the error and result (if any) of the final attempt.
 *
 * @name retry
 * @static
 * @memberOf module:ControlFlow
 * @method
 * @category Control Flow
 * @see [async.retryable]{@link module:ControlFlow.retryable}
 * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - Can be either an
 * object with `times` and `interval` or a number.
 * * `times` - The number of attempts to make before giving up.  The default
 *   is `5`.
 * * `interval` - The time to wait between retries, in milliseconds.  The
 *   default is `0`. The interval may also be specified as a function of the
 *   retry count (see example).
 * * `errorFilter` - An optional synchronous function that is invoked on
 *   erroneous result. If it returns `true` the retry attempts will continue;
 *   if the function returns `false` the retry flow is aborted with the current
 *   attempt's error and result being returned to the final callback.
 *   Invoked with (err).
 * * If `opts` is a number, the number specifies the number of times to retry,
 *   with the default interval of `0`.
 * @param {AsyncFunction} task - An async function to retry.
 * Invoked with (callback).
 * @param {Function} [callback] - An optional callback which is called when the
 * task has succeeded, or after the final failed attempt. It receives the `err`
 * and `result` arguments of the last attempt at completing the `task`. Invoked
 * with (err, results).
 * @returns {Promise} a promise if no callback provided
 *
 * @example
 *
 * // The `retry` function can be used as a stand-alone control flow by passing
 * // a callback, as shown below:
 *
 * // try calling apiMethod 3 times
 * async.retry(3, apiMethod, function(err, result) {
 *     // do something with the result
 * });
 *
 * // try calling apiMethod 3 times, waiting 200 ms between each retry
 * async.retry({times: 3, interval: 200}, apiMethod, function(err, result) {
 *     // do something with the result
 * });
 *
 * // try calling apiMethod 10 times with exponential backoff
 * // (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds)
 * async.retry({
 *   times: 10,
 *   interval: function(retryCount) {
 *     return 50 * Math.pow(2, retryCount);
 *   }
 * }, apiMethod, function(err, result) {
 *     // do something with the result
 * });
 *
 * // try calling apiMethod the default 5 times no delay between each retry
 * async.retry(apiMethod, function(err, result) {
 *     // do something with the result
 * });
 *
 * // try calling apiMethod only when error condition satisfies, all other
 * // errors will abort the retry control flow and return to final callback
 * async.retry({
 *   errorFilter: function(err) {
 *     return err.message === 'Temporary error'; // only retry on a specific error
 *   }
 * }, apiMethod, function(err, result) {
 *     // do something with the result
 * });
 *
 * // to retry individual methods that are not as reliable within other
 * // control flow functions, use the `retryable` wrapper:
 * async.auto({
 *     users: api.getUsers.bind(api),
 *     payments: async.retryable(3, api.getPayments.bind(api))
 * }, function(err, results) {
 *     // do something with the results
 * });
 *
 */
const DEFAULT_TIMES = 5;
const DEFAULT_INTERVAL = 0;

function retry(opts, task, callback) {
    var options = {
        times: DEFAULT_TIMES,
        intervalFunc: constant(DEFAULT_INTERVAL)
    };

    if (arguments.length < 3 && typeof opts === 'function') {
        callback = task || (0, _promiseCallback.promiseCallback)();
        task = opts;
    } else {
        parseTimes(options, opts);
        callback = callback || (0, _promiseCallback.promiseCallback)();
    }

    if (typeof task !== 'function') {
        throw new Error("Invalid arguments for async.retry");
    }

    var _task = (0, _wrapAsync2.default)(task);

    var attempt = 1;
    function retryAttempt() {
        _task((err, ...args) => {
            if (err === false) return;
            if (err && attempt++ < options.times && (typeof options.errorFilter != 'function' || options.errorFilter(err))) {
                setTimeout(retryAttempt, options.intervalFunc(attempt - 1));
            } else {
                callback(err, ...args);
            }
        });
    }

    retryAttempt();
    return callback[_promiseCallback.PROMISE_SYMBOL];
}

function parseTimes(acc, t) {
    if (typeof t === 'object') {
        acc.times = +t.times || DEFAULT_TIMES;

        acc.intervalFunc = typeof t.interval === 'function' ? t.interval : constant(+t.interval || DEFAULT_INTERVAL);

        acc.errorFilter = t.errorFilter;
    } else if (typeof t === 'number' || typeof t === 'string') {
        acc.times = +t || DEFAULT_TIMES;
    } else {
        throw new Error("Invalid arguments for async.retry");
    }
}
module.exports = exports.default;

Directory Contents

Dirs: 2 × Files: 110

Name Size Perms Modified Actions
dist DIR
- drwxr-xr-x 2026-03-14 01:49:20
Edit Download
internal DIR
- drwxr-xr-x 2026-03-14 01:49:20
Edit Download
127 B lr--r--r-- 2026-03-14 01:49:20
Edit Download
3.48 KB lrw-r--r-- 2026-02-21 00:53:20
Edit Download
1.71 KB lrw-r--r-- 2026-02-21 00:53:22
Edit Download
1.61 KB lrw-r--r-- 2026-02-21 00:53:22
Edit Download
3.71 KB lrw-r--r-- 2026-02-21 00:53:24
Edit Download
1.74 KB lrw-r--r-- 2026-02-21 00:53:24
Edit Download
1.64 KB lrw-r--r-- 2026-02-21 00:53:28
Edit Download
217 B lrw-r--r-- 2026-02-21 00:53:28
Edit Download
1.94 KB lrw-r--r-- 2026-02-21 00:53:30
Edit Download
1.27 KB lrw-r--r-- 2026-02-21 00:53:34
Edit Download
3.67 KB lrw-r--r-- 2026-02-21 00:53:38
Edit Download
11.58 KB lrw-r--r-- 2026-02-21 00:53:40
Edit Download
6.93 KB lrw-r--r-- 2026-02-21 00:53:42
Edit Download
239 B lrw-r--r-- 2026-02-21 00:54:22
Edit Download
2.68 KB lrw-r--r-- 2026-02-21 00:53:44
Edit Download
3.27 KB lrw-r--r-- 2026-02-21 00:53:44
Edit Download
32.70 KB lrw-r--r-- 2026-02-21 00:54:22
Edit Download
1.53 KB lrw-r--r-- 2026-02-21 00:53:46
Edit Download
3.57 KB lrw-r--r-- 2026-02-21 00:53:46
Edit Download
2.04 KB lrw-r--r-- 2026-02-21 00:53:46
Edit Download
1.44 KB lrw-r--r-- 2026-02-21 00:53:48
Edit Download
302 B lrw-r--r-- 2026-02-21 00:53:50
Edit Download
3.17 KB lrw-r--r-- 2026-02-21 00:53:50
Edit Download
1.79 KB lrw-r--r-- 2026-02-21 00:53:50
Edit Download
1.70 KB lrw-r--r-- 2026-02-21 00:53:52
Edit Download
1.27 KB lrw-r--r-- 2026-02-21 00:53:54
Edit Download
2.25 KB lrw-r--r-- 2026-02-21 00:53:54
Edit Download
1.66 KB lrw-r--r-- 2026-02-21 00:53:56
Edit Download
2.25 KB lrw-r--r-- 2026-02-21 00:53:56
Edit Download
2.28 KB lrw-r--r-- 2026-02-21 00:53:58
Edit Download
3.93 KB lrw-r--r-- 2026-02-21 00:53:58
Edit Download
1.75 KB lrw-r--r-- 2026-02-21 00:53:58
Edit Download
5.61 KB lrw-r--r-- 2026-02-21 00:53:58
Edit Download
1.60 KB lrw-r--r-- 2026-02-21 00:53:58
Edit Download
1.30 KB lrw-r--r-- 2026-02-21 00:53:58
Edit Download
1.54 KB lrw-r--r-- 2026-02-21 00:54:00
Edit Download
2.26 KB lrw-r--r-- 2026-02-21 00:54:00
Edit Download
3.48 KB lrw-r--r-- 2026-02-21 00:54:00
Edit Download
1.71 KB lrw-r--r-- 2026-02-21 00:54:00
Edit Download
1.61 KB lrw-r--r-- 2026-02-21 00:54:00
Edit Download
2.83 KB lrw-r--r-- 2026-02-21 00:54:00
Edit Download
1.62 KB lrw-r--r-- 2026-02-21 00:54:00
Edit Download
1.51 KB lrw-r--r-- 2026-02-21 00:54:00
Edit Download
3.17 KB lrw-r--r-- 2026-02-21 00:54:00
Edit Download
1.79 KB lrw-r--r-- 2026-02-21 00:54:00
Edit Download
1.70 KB lrw-r--r-- 2026-02-21 00:54:00
Edit Download
3.57 KB lrw-r--r-- 2026-02-21 00:54:02
Edit Download
2.04 KB lrw-r--r-- 2026-02-21 00:54:02
Edit Download
1.44 KB lrw-r--r-- 2026-02-21 00:54:02
Edit Download
4.76 KB lrw-r--r-- 2026-02-21 00:54:02
Edit Download
1.47 KB lrw-r--r-- 2026-02-21 00:54:02
Edit Download
3.93 KB lrw-r--r-- 2026-02-21 00:54:02
Edit Download
1.75 KB lrw-r--r-- 2026-02-21 00:54:02
Edit Download
5.61 KB lrw-r--r-- 2026-02-21 00:54:02
Edit Download
1.60 KB lrw-r--r-- 2026-02-21 00:54:04
Edit Download
1.30 KB lrw-r--r-- 2026-02-21 00:54:04
Edit Download
1.54 KB lrw-r--r-- 2026-02-21 00:54:04
Edit Download
2.07 KB lrw-r--r-- 2026-02-21 00:54:04
Edit Download
3.51 KB lrw-r--r-- 2026-02-21 00:54:04
Edit Download
2.39 KB lrw-r--r-- 2026-02-21 00:54:04
Edit Download
1.30 KB lrw-r--r-- 2026-02-21 00:54:04
Edit Download
19.47 KB lrw-r--r-- 2026-02-21 00:54:04
Edit Download
4.76 KB lrw-r--r-- 2026-02-21 00:54:04
Edit Download
1.04 KB lrw-r--r-- 2026-02-21 00:53:18
Edit Download
1.17 KB lrw-r--r-- 2026-02-21 00:54:04
Edit Download
4.49 KB lrw-r--r-- 2026-02-21 00:54:04
Edit Download
1.58 KB lrw-r--r-- 2026-02-21 00:54:04
Edit Download
1.48 KB lrw-r--r-- 2026-02-21 00:54:06
Edit Download
4.48 KB lrw-r--r-- 2026-02-21 00:54:06
Edit Download
2.07 KB lrw-r--r-- 2026-02-21 00:54:06
Edit Download
1.35 KB lrw-r--r-- 2026-02-21 00:54:06
Edit Download
3.00 KB lrw-r--r-- 2026-02-21 00:54:08
Edit Download
1.44 KB lrw-r--r-- 2026-02-21 00:54:08
Edit Download
2.15 KB lrw-r--r-- 2026-02-21 00:54:22
Edit Download
5.44 KB lrw-r--r-- 2026-02-21 00:54:08
Edit Download
1.48 KB lrw-r--r-- 2026-02-21 00:54:08
Edit Download
1.41 KB lrw-r--r-- 2026-02-21 00:54:08
Edit Download
626 B lrw-r--r-- 2026-02-21 00:54:10
Edit Download
2.08 KB lrw-r--r-- 2026-02-21 00:54:10
Edit Download
3.14 KB lrw-r--r-- 2026-02-21 00:54:22
Edit Download
4.76 KB lrw-r--r-- 2026-02-21 00:54:10
Edit Download
1.47 KB lrw-r--r-- 2026-02-21 00:54:10
Edit Download
2.21 KB lrw-r--r-- 2026-02-21 00:54:10
Edit Download
2.39 KB lrw-r--r-- 2026-02-21 00:54:10
Edit Download
2.61 KB lrw-r--r-- 2026-02-21 00:54:12
Edit Download
1.54 KB lrw-r--r-- 2026-02-21 00:54:12
Edit Download
1.44 KB lrw-r--r-- 2026-02-21 00:54:12
Edit Download
5.39 KB lrw-r--r-- 2026-02-21 00:54:12
Edit Download
2.48 KB lrw-r--r-- 2026-02-21 00:54:12
Edit Download
2.83 KB lrw-r--r-- 2026-02-21 00:54:14
Edit Download
1.62 KB lrw-r--r-- 2026-02-21 00:54:14
Edit Download
1.51 KB lrw-r--r-- 2026-02-21 00:54:16
Edit Download
2.59 KB lrw-r--r-- 2026-02-21 00:54:16
Edit Download
5.69 KB lrw-r--r-- 2026-02-21 00:54:16
Edit Download
1.36 KB lrw-r--r-- 2026-02-21 00:54:18
Edit Download
3.71 KB lrw-r--r-- 2026-02-21 00:54:18
Edit Download
1.74 KB lrw-r--r-- 2026-02-21 00:54:18
Edit Download
1.64 KB lrw-r--r-- 2026-02-21 00:54:18
Edit Download
6.06 KB lrw-r--r-- 2026-02-21 00:54:20
Edit Download
2.69 KB lrw-r--r-- 2026-02-21 00:54:20
Edit Download
1.45 KB lrw-r--r-- 2026-02-21 00:54:20
Edit Download
1.42 KB lrw-r--r-- 2026-02-21 00:54:20
Edit Download
1.04 KB lrw-r--r-- 2026-02-21 00:54:20
Edit Download
5.43 KB lrw-r--r-- 2026-02-21 00:54:20
Edit Download
2.48 KB lrw-r--r-- 2026-02-21 00:54:20
Edit Download
665 B lrw-r--r-- 2026-02-21 00:54:20
Edit Download
2.03 KB lrw-r--r-- 2026-02-21 00:54:20
Edit Download
3.13 KB lrw-r--r-- 2026-02-21 00:54:20
Edit Download
2.28 KB lrw-r--r-- 2026-02-21 00:54:22
Edit Download
3.67 KB lrw-r--r-- 2026-02-21 00:54:22
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).