1'use strict'; 2 3Object.defineProperty(exports, "__esModule", { 4 value: true 5}); 6exports.default = cargo; 7 8var _queue = require('./internal/queue.js'); 9 10var _queue2 = _interopRequireDefault(_queue); 11 12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 13 14/** 15 * Creates a `cargoQueue` object with the specified payload. Tasks added to the 16 * cargoQueue will be processed together (up to the `payload` limit) in `concurrency` parallel workers. 17 * If the all `workers` are in progress, the task is queued until one becomes available. Once 18 * a `worker` has completed some tasks, each callback of those tasks is 19 * called. Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966) 20 * for how `cargo` and `queue` work. 21 * 22 * While [`queue`]{@link module:ControlFlow.queue} passes only one task to one of a group of workers 23 * at a time, and [`cargo`]{@link module:ControlFlow.cargo} passes an array of tasks to a single worker, 24 * the cargoQueue passes an array of tasks to multiple parallel workers. 25 * 26 * @name cargoQueue 27 * @static 28 * @memberOf module:ControlFlow 29 * @method 30 * @see [async.queue]{@link module:ControlFlow.queue} 31 * @see [async.cargo]{@link module:ControlFLow.cargo} 32 * @category Control Flow 33 * @param {AsyncFunction} worker - An asynchronous function for processing an array 34 * of queued tasks. Invoked with `(tasks, callback)`. 35 * @param {number} [concurrency=1] - An `integer` for determining how many 36 * `worker` functions should be run in parallel. If omitted, the concurrency 37 * defaults to `1`. If the concurrency is `0`, an error is thrown. 38 * @param {number} [payload=Infinity] - An optional `integer` for determining 39 * how many tasks should be processed per round; if omitted, the default is 40 * unlimited. 41 * @returns {module:ControlFlow.QueueObject} A cargoQueue object to manage the tasks. Callbacks can 42 * attached as certain properties to listen for specific events during the 43 * lifecycle of the cargoQueue and inner queue. 44 * @example 45 * 46 * // create a cargoQueue object with payload 2 and concurrency 2 47 * var cargoQueue = async.cargoQueue(function(tasks, callback) { 48 * for (var i=0; i<tasks.length; i++) { 49 * console.log('hello ' + tasks[i].name); 50 * } 51 * callback(); 52 * }, 2, 2); 53 * 54 * // add some items 55 * cargoQueue.push({name: 'foo'}, function(err) { 56 * console.log('finished processing foo'); 57 * }); 58 * cargoQueue.push({name: 'bar'}, function(err) { 59 * console.log('finished processing bar'); 60 * }); 61 * cargoQueue.push({name: 'baz'}, function(err) { 62 * console.log('finished processing baz'); 63 * }); 64 * cargoQueue.push({name: 'boo'}, function(err) { 65 * console.log('finished processing boo'); 66 * }); 67 */ 68function cargo(worker, concurrency, payload) { 69 return (0, _queue2.default)(worker, concurrency, payload); 70} 71module.exports = exports['default'];