diff options
author | Hubert Argasinski <argasinski.hubert@gmail.com> | 2016-03-29 04:09:31 -0700 |
---|---|---|
committer | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-04-12 18:46:24 -0400 |
commit | 982674c1ac82865c0dbf31ae2ec611ec1cdcd21a (patch) | |
tree | 5424e3dd0884523097218d09bbde36bdf5446cad /lib/each.js | |
parent | b40ece78ac5195cd010960ace46833a48d84d3db (diff) | |
download | async-982674c1ac82865c0dbf31ae2ec611ec1cdcd21a.tar.gz |
jsdoc-style documentation for 'collection' methods
Converted documentation from README to jsdoc-style for respective
methods. Currently, only done for 'collection' methods.
jsdoc-style documentation - fixed 'collection' methods documentation
Only the base functions now contain an example, while the `series` and
`limit` versions simply contain a reference to the base function. Fixed
styling issue and misspelled tag.
Diffstat (limited to 'lib/each.js')
-rw-r--r-- | lib/each.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/each.js b/lib/each.js index d81763a..f2c9929 100644 --- a/lib/each.js +++ b/lib/each.js @@ -3,4 +3,62 @@ import eachLimit from './eachLimit'; import doLimit from './internal/doLimit'; +/** + * Applies the function `iteratee` to each item in `coll`, in parallel. + * The `iteratee` is called with an item from the list, and a callback for when + * it has finished. If the `iteratee` passes an error to its `callback`, the + * main `callback` (for the `each` function) is immediately called with the + * error. + * + * Note, that since this function applies `iteratee` to each item in parallel, + * there is no guarantee that the iteratee functions will complete in order. + * + * @name each + * @static + * @memberOf async + * @alias forEach + * @category Collection + * @param {Array|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each item + * in `coll`. The iteratee 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. The array index is not + * passed to the iteratee. Invoked with (item, callback). If you need the index, + * use `eachOf`. + * @param {Function} [callback] - A callback which is called when all + * `iteratee` functions have finished, or an error occurs. Invoked with (err). + * @example + * + * // assuming openFiles is an array of file names and saveFile is a function + * // to save the modified contents of that file: + * + * async.each(openFiles, saveFile, function(err){ + * // if any of the saves produced an error, err would equal that error + * }); + * + * // assuming openFiles is an array of file names + * async.each(openFiles, function(file, callback) { + * + * // Perform operation on file here. + * console.log('Processing file ' + file); + * + * if( file.length > 32 ) { + * console.log('This file name is too long'); + * callback('File name too long'); + * } else { + * // Do work to process file here + * console.log('File processed'); + * callback(); + * } + * }, function(err) { + * // if any of the file processing produced an error, err would equal that error + * if( err ) { + * // One of the iterations produced an error. + * // All processing will now stop. + * console.log('A file failed to process'); + * } else { + * console.log('All files have been processed successfully'); + * } + * }); + */ export default doLimit(eachLimit, Infinity); |