diff options
author | Alexander Early <aearly@fluid.com> | 2015-01-19 23:53:49 -0800 |
---|---|---|
committer | Alexander Early <aearly@fluid.com> | 2015-01-19 23:53:49 -0800 |
commit | 6d612c8bceff7a88ebcc263a139f336adec79e9e (patch) | |
tree | fc7cc42cf0687d0ce6e58f6f688b40ed1378bbb1 /README.md | |
parent | da40afa5ee2bca3cb92d9f7fd8bc83c5fdbfa1e1 (diff) | |
download | async-6d612c8bceff7a88ebcc263a139f336adec79e9e.tar.gz |
adding docs for forEachOf methods
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -119,6 +119,9 @@ Usage: * [`each`](#each) * [`eachSeries`](#eachSeries) * [`eachLimit`](#eachLimit) +* [`forEachOf`](#forEachOf) +* [`forEachOfSeries`](#forEachOfSeries) +* [`forEachOfLimit`](#forEachOfLimit) * [`map`](#map) * [`mapSeries`](#mapSeries) * [`mapLimit`](#mapLimit) @@ -282,6 +285,53 @@ async.eachLimit(documents, 20, requestApi, function(err){ --------------------------------------- +<a name="forEachOf" /> + +### forEachOf(obj, iterator, callback) + +Like `each`, except that it iterates over objects, and passes the key as the second argument to the iterator. + +__Arguments__ + +* `obj` - An object or array to iterate over. +* `iterator(item, key, callback)` - A function to apply to each item in `obj`. +The `key` is the item's key, or index in the case of an array. The iterator is +passed a `callback(err)` which must be called once it has completed. If no +error has occurred, the callback should be run without arguments or with an +explicit `null` argument. +* `callback(err)` - A callback which is called when all `iterator` functions have finished, or an error occurs. + +__Example__ + +```js +var obj = {a: 1, b: 2, c: 3}; + +async.forEachOf(obj, function (value, key, callback) { + console.log(value + ":" + key) // 1:a, 2:b, 3:c, etc... + callback(); +}, function (err) { + +}) +``` + +--------------------------------------- + +<a name="forEachOfSeries" /> + +### forEachOfSeries(obj, iterator, callback) + +Like [`forEachOf`](#forEachOf), except only one `iterator` is run at a time. The order of execution is not guaranteed for objects, but it will be for arrays. +--------------------------------------- + +<a name="forEachOfLimit" /> + +### forEachOfLimit(obj, limit, iterator, callback) + +Like [`forEachOf`](#forEachOf), except only one the number of `iterator`s running at a time is controlled by `limit`. The order of execution is not guaranteed for objects, but it will be for arrays. + + +--------------------------------------- + <a name="map" /> ### map(arr, iterator, callback) |