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

import isArray from 'lodash/isArray';
import noop from 'lodash/noop';
import once from 'lodash/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();
    for (let i = 0; i < tasks.length; i++) {
        tasks[i](cb);
    }
}