Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

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