summaryrefslogtreecommitdiff
path: root/README.md
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 /README.md
parenta8c285ba7fbc7084c25c3af9b9eeff1e9b63bd62 (diff)
downloadasync-91a7e520e5cd514db53810ce9c1f9563a6566808.tar.gz
Add race method
Diffstat (limited to 'README.md')
-rw-r--r--README.md41
1 files changed, 41 insertions, 0 deletions
diff --git a/README.md b/README.md
index 9763875..06ec85b 100644
--- a/README.md
+++ b/README.md
@@ -221,6 +221,7 @@ Some functions are also available in the following forms:
* [`retry`](#retry)
* [`iterator`](#iterator)
* [`times`](#times), `timesSeries`, `timesLimit`
+* [`race`](#race)
### Utils
@@ -1655,6 +1656,46 @@ __Related__
---------------------------------------
+<a name="race" />
+### race(tasks, [callback])
+
+Runs the `tasks` array of functions in parallel, without waiting until the
+previous function has completed. Once any the `tasks` completed or pass an
+error to its callback, the main `callback` is immediately called. It's
+equivalent to `Promise.race()`.
+
+__Arguments__
+
+* `tasks` - An array containing functions to run. Each function is passed
+ a `callback(err, result)` which it must call on completion with an error `err`
+ (which can be `null`) and an optional `result` value.
+* `callback(err, result)` - A callback to run once any of the
+ functions have completed. This function gets an error or result from the
+ first function that completed.
+
+__Example__
+
+```js
+async.race([
+ function(callback){
+ setTimeout(function(){
+ callback(null, 'one');
+ }, 200);
+ },
+ function(callback){
+ setTimeout(function(){
+ callback(null, 'two');
+ }, 100);
+ }
+],
+// main callback
+function(err, result){
+ // the result will be equal to 'two' as it finishes earlier
+});
+```
+
+---------------------------------------
+
<a name="memoize"></a>
### memoize(fn, [hasher])