diff options
author | Alexander Early <alexander.early@gmail.com> | 2015-05-20 22:29:37 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2015-05-20 22:29:52 -0700 |
commit | a2c8cc8648021c9bf7b43c13ed196788491eff87 (patch) | |
tree | 305dfca66b333cd2bea07dbbbc4051de01ef9fff | |
parent | 0845604ee397986114f0f1028412478d3d02f2d2 (diff) | |
download | async-a2c8cc8648021c9bf7b43c13ed196788491eff87.tar.gz |
added additional detectSeries test, clarified docs. Closes #534
-rw-r--r-- | README.md | 11 | ||||
-rwxr-xr-x | test/test-async.js | 10 |
2 files changed, 17 insertions, 4 deletions
@@ -552,11 +552,11 @@ __Arguments__ * `arr` - An array to iterate over. * `iterator(item, callback)` - A truth test to apply to each item in `arr`. The iterator is passed a `callback(truthValue)` which must be called with a - boolean argument once it has completed. + boolean argument once it has completed. **Note: this callback does not take an error as its first argument.** * `callback(result)` - A callback which is called as soon as any iterator returns `true`, or after all the `iterator` functions have finished. Result will be the first item in the array that passes the truth test (iterator) or the - value `undefined` if none passed. + value `undefined` if none passed. **Note: this callback does not take an error as its first argument.** __Example__ @@ -644,12 +644,13 @@ __Arguments__ * `arr` - An array to iterate over. * `iterator(item, callback)` - A truth test to apply to each item in the array - in parallel. The iterator is passed a callback(truthValue) which must be + in parallel. The iterator is passed a `callback(truthValue)`` which must be called with a boolean argument once it has completed. * `callback(result)` - A callback which is called as soon as any iterator returns `true`, or after all the iterator functions have finished. Result will be either `true` or `false` depending on the values of the async tests. + **Note: the callbacks do not take an error as their first argument.** __Example__ ```js @@ -674,12 +675,14 @@ __Arguments__ * `arr` - An array to iterate over. * `iterator(item, callback)` - A truth test to apply to each item in the array - in parallel. The iterator is passed a callback(truthValue) which must be + in parallel. The iterator is passed a `callback(truthValue)` which must be called with a boolean argument once it has completed. * `callback(result)` - A callback which is called after all the `iterator` functions have finished. Result will be either `true` or `false` depending on the values of the async tests. + **Note: the callbacks do not take an error as their first argument.** + __Example__ ```js diff --git a/test/test-async.js b/test/test-async.js index 64c33f9..fe927de 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -1895,6 +1895,16 @@ exports['detectSeries - multiple matches'] = function(test){ }, 200); }; +exports['detectSeries - ensure stop'] = function (test) { + async.detectSeries([1, 2, 3, 4, 5], function (num, cb) { + if (num > 3) throw new Error("detectSeries did not stop iterating"); + cb(num === 3); + }, function (result) { + test.equals(result, 3); + test.done(); + }); +}; + exports['sortBy'] = function(test){ async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){ setTimeout(function(){callback(null, x.a);}, 0); |