summaryrefslogtreecommitdiff
path: root/lib/race.js
diff options
context:
space:
mode:
authorJorge Bay Gondra <jorgebaygondra@gmail.com>2016-02-25 20:39:06 +0100
committerJorge Bay Gondra <jorgebaygondra@gmail.com>2016-02-26 12:09:33 +0100
commit91a7e520e5cd514db53810ce9c1f9563a6566808 (patch)
tree942fb1ede03bad89e5f181e5851f748bb3f37fd5 /lib/race.js
parenta8c285ba7fbc7084c25c3af9b9eeff1e9b63bd62 (diff)
downloadasync-91a7e520e5cd514db53810ce9c1f9563a6566808.tar.gz
Add race method
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);
+ }
+}