Server IP : 85.214.239.14 / Your IP : 18.222.164.159 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/root/lib/node_modules/pm2/node_modules/@pm2/io/node_modules/async/ |
Upload File : |
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = reduce; var _eachOfSeries = require('./eachOfSeries'); var _eachOfSeries2 = _interopRequireDefault(_eachOfSeries); var _noop = require('lodash/noop'); var _noop2 = _interopRequireDefault(_noop); var _once = require('./internal/once'); var _once2 = _interopRequireDefault(_once); var _wrapAsync = require('./internal/wrapAsync'); var _wrapAsync2 = _interopRequireDefault(_wrapAsync); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Reduces `coll` into a single value using an async `iteratee` to return each * successive step. `memo` is the initial state of the reduction. This function * only operates in series. * * For performance reasons, it may make sense to split a call to this function * into a parallel map, and then use the normal `Array.prototype.reduce` on the * results. This function is for situations where each step in the reduction * needs to be async; if you can get the data before reducing it, then it's * probably a good idea to do so. * * @name reduce * @static * @memberOf module:Collections * @method * @alias inject * @alias foldl * @category Collection * @param {Array|Iterable|Object} coll - A collection to iterate over. * @param {*} memo - The initial state of the reduction. * @param {AsyncFunction} iteratee - A function applied to each item in the * array to produce the next step in the reduction. * The `iteratee` should complete with the next state of the reduction. * If the iteratee complete with an error, the reduction is stopped and the * main `callback` is immediately called with the error. * Invoked with (memo, item, callback). * @param {Function} [callback] - A callback which is called after all the * `iteratee` functions have finished. Result is the reduced value. Invoked with * (err, result). * @example * * async.reduce([1,2,3], 0, function(memo, item, callback) { * // pointless async: * process.nextTick(function() { * callback(null, memo + item) * }); * }, function(err, result) { * // result is now equal to the last value of memo, which is 6 * }); */ function reduce(coll, memo, iteratee, callback) { callback = (0, _once2.default)(callback || _noop2.default); var _iteratee = (0, _wrapAsync2.default)(iteratee); (0, _eachOfSeries2.default)(coll, function (x, i, callback) { _iteratee(memo, x, function (err, v) { memo = v; callback(err); }); }, function (err) { callback(err, memo); }); } module.exports = exports['default'];