source: trip-planner-front/node_modules/async/reflectAll.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.7 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = reflectAll;
7
8var _reflect = require('./reflect');
9
10var _reflect2 = _interopRequireDefault(_reflect);
11
12var _isArray = require('lodash/isArray');
13
14var _isArray2 = _interopRequireDefault(_isArray);
15
16var _arrayMap2 = require('lodash/_arrayMap');
17
18var _arrayMap3 = _interopRequireDefault(_arrayMap2);
19
20var _baseForOwn = require('lodash/_baseForOwn');
21
22var _baseForOwn2 = _interopRequireDefault(_baseForOwn);
23
24function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
26/**
27 * A helper function that wraps an array or an object of functions with `reflect`.
28 *
29 * @name reflectAll
30 * @static
31 * @memberOf module:Utils
32 * @method
33 * @see [async.reflect]{@link module:Utils.reflect}
34 * @category Util
35 * @param {Array|Object|Iterable} tasks - The collection of
36 * [async functions]{@link AsyncFunction} to wrap in `async.reflect`.
37 * @returns {Array} Returns an array of async functions, each wrapped in
38 * `async.reflect`
39 * @example
40 *
41 * let tasks = [
42 * function(callback) {
43 * setTimeout(function() {
44 * callback(null, 'one');
45 * }, 200);
46 * },
47 * function(callback) {
48 * // do some more stuff but error ...
49 * callback(new Error('bad stuff happened'));
50 * },
51 * function(callback) {
52 * setTimeout(function() {
53 * callback(null, 'two');
54 * }, 100);
55 * }
56 * ];
57 *
58 * async.parallel(async.reflectAll(tasks),
59 * // optional callback
60 * function(err, results) {
61 * // values
62 * // results[0].value = 'one'
63 * // results[1].error = Error('bad stuff happened')
64 * // results[2].value = 'two'
65 * });
66 *
67 * // an example using an object instead of an array
68 * let tasks = {
69 * one: function(callback) {
70 * setTimeout(function() {
71 * callback(null, 'one');
72 * }, 200);
73 * },
74 * two: function(callback) {
75 * callback('two');
76 * },
77 * three: function(callback) {
78 * setTimeout(function() {
79 * callback(null, 'three');
80 * }, 100);
81 * }
82 * };
83 *
84 * async.parallel(async.reflectAll(tasks),
85 * // optional callback
86 * function(err, results) {
87 * // values
88 * // results.one.value = 'one'
89 * // results.two.error = 'two'
90 * // results.three.value = 'three'
91 * });
92 */
93function reflectAll(tasks) {
94 var results;
95 if ((0, _isArray2.default)(tasks)) {
96 results = (0, _arrayMap3.default)(tasks, _reflect2.default);
97 } else {
98 results = {};
99 (0, _baseForOwn2.default)(tasks, function (task, key) {
100 results[key] = _reflect2.default.call(this, task);
101 });
102 }
103 return results;
104}
105module.exports = exports['default'];
Note: See TracBrowser for help on using the repository browser.