summaryrefslogtreecommitdiff
path: root/lib/internal/parallel.js
blob: 52b03037a1299ac7bdc092da7e99990c034c67dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict';

import noop from 'lodash/noop';
import isArrayLike from 'lodash/isArrayLike';
import rest from 'lodash/rest';

export default function _parallel(eachfn, tasks, callback) {
    callback = callback || noop;
    var results = isArrayLike(tasks) ? [] : {};

    eachfn(tasks, function (task, key, callback) {
        task(rest(function (err, args) {
            if (args.length <= 1) {
                args = args[0];
            }
            results[key] = args;
            callback(err);
        }));
    }, function (err) {
        callback(err, results);
    });
}