Projekt

Obecné

Profil

Stáhnout (1.98 KB) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
'use strict';
2
3
Object.defineProperty(exports, "__esModule", {
4
    value: true
5
});
6
7
exports.default = function (opts, task) {
8
    if (!task) {
9
        task = opts;
10
        opts = null;
11
    }
12
    var _task = (0, _wrapAsync2.default)(task);
13
    return (0, _initialParams2.default)(function (args, callback) {
14
        function taskFn(cb) {
15
            _task.apply(null, args.concat(cb));
16
        }
17
18
        if (opts) (0, _retry2.default)(opts, taskFn, callback);else (0, _retry2.default)(taskFn, callback);
19
    });
20
};
21
22
var _retry = require('./retry');
23
24
var _retry2 = _interopRequireDefault(_retry);
25
26
var _initialParams = require('./internal/initialParams');
27
28
var _initialParams2 = _interopRequireDefault(_initialParams);
29
30
var _wrapAsync = require('./internal/wrapAsync');
31
32
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
33
34
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
36
module.exports = exports['default'];
37
38
/**
39
 * A close relative of [`retry`]{@link module:ControlFlow.retry}.  This method
40
 * wraps a task and makes it retryable, rather than immediately calling it
41
 * with retries.
42
 *
43
 * @name retryable
44
 * @static
45
 * @memberOf module:ControlFlow
46
 * @method
47
 * @see [async.retry]{@link module:ControlFlow.retry}
48
 * @category Control Flow
49
 * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - optional
50
 * options, exactly the same as from `retry`
51
 * @param {AsyncFunction} task - the asynchronous function to wrap.
52
 * This function will be passed any arguments passed to the returned wrapper.
53
 * Invoked with (...args, callback).
54
 * @returns {AsyncFunction} The wrapped function, which when invoked, will
55
 * retry on an error, based on the parameters specified in `opts`.
56
 * This function will accept the same parameters as `task`.
57
 * @example
58
 *
59
 * async.auto({
60
 *     dep1: async.retryable(3, getFromFlakyService),
61
 *     process: ["dep1", async.retryable(3, function (results, cb) {
62
 *         maybeProcessData(results.dep1, cb);
63
 *     })]
64
 * }, callback);
65
 */