summaryrefslogtreecommitdiff
path: root/lib/race.js
blob: b89a5db37996f8836c5df0be3391802bec8fc58c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
'use strict';

import isArray from 'lodash/isArray';
import each from 'lodash/each';
import noop from 'lodash/noop';
import once from './internal/once';

export default function race(tasks, cb) {
    cb = once(cb || noop);
    if (!isArray(tasks)) return cb(new TypeError('First argument to race must be an array of functions'));
    if (!tasks.length) return cb();
    each(tasks, function (task) {
        task(cb);
    });
}