Recieve an array of functions (usually async) to call in parallel, each function receives a callback as first argument that it should call, when it completes. After everything is complete, main callback is called. Passing truthy value to the callback as a first argument will interrupt the proces
(queue, cb)
| 394 | @param {Function} cb Main callback that is called in the end, or in case of erro |
| 395 | */ |
| 396 | function inParallel(queue, cb) { |
| 397 | var count = 0, num = queue.length, cbArgs = new Array(num); |
| 398 | |
| 399 | each(queue, function(fn, i) { |
| 400 | fn(function(error) { |
| 401 | if (error) { |
| 402 | return cb(error); |
| 403 | } |
| 404 | |
| 405 | var args = [].slice.call(arguments); |
| 406 | args.shift(); // strip error - undefined or not |
| 407 | |
| 408 | cbArgs[i] = args; |
| 409 | count++; |
| 410 | |
| 411 | if (count === num) { |
| 412 | cbArgs.unshift(null); |
| 413 | cb.apply(this, cbArgs); |
| 414 | } |
| 415 | }); |
| 416 | }); |
| 417 | } |
| 418 | |
| 419 | |
| 420 | /** |