summaryrefslogtreecommitdiff
path: root/lib/race.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/race.js')
-rw-r--r--lib/race.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/race.js b/lib/race.js
new file mode 100644
index 0000000..4a5f8a5
--- /dev/null
+++ b/lib/race.js
@@ -0,0 +1,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);
+ }
+}