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