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