Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions lib/applyEach.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ import applyEach from './internal/applyEach.js'
import map from './map.js'

/**
* Applies the provided arguments to each function in the array, calling
* `callback` after all functions have completed. If you only provide the first
* argument, `fns`, then it will return a function which lets you pass in the
* arguments as if it were a single function call. If more arguments are
* provided, `callback` is required while `args` is still optional. The results
* for each of the applied async functions are passed to the final callback
* as an array.
* Returns a function that applies the provided arguments to each function in
* `fns`. Pass a callback to the returned function to receive the results as an
* array after all functions have completed. Calling the returned function
* without a callback returns a Promise for the results.
*
* @name applyEach
* @static
Expand All @@ -19,11 +16,8 @@ import map from './map.js'
* to all call with the same arguments
* @param {...*} [args] - any number of separate arguments to pass to the
* function.
* @param {Function} [callback] - the final argument should be the callback,
* called when all functions have completed processing.
* @returns {AsyncFunction} - Returns a function that takes no args other than
* an optional callback, that is the result of applying the `args` to each
* of the functions.
* an optional callback. If no callback is passed, it returns a Promise.
* @example
*
* const appliedFn = async.applyEach([enableSearch, updateSchema], 'bucket')
Expand All @@ -33,7 +27,12 @@ import map from './map.js'
* // results[1] is the results for `updateSchema`
* });
*
* // partial application example:
* // or use a Promise:
* appliedFn().then(results => {
* console.log(results);
* });
*
* // apply the same functions to each bucket:
* async.each(
* buckets,
* async (bucket) => async.applyEach([enableSearch, updateSchema], bucket)(),
Expand Down
6 changes: 2 additions & 4 deletions lib/applyEachSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import mapSeries from './mapSeries.js'
* call with the same arguments
* @param {...*} [args] - any number of separate arguments to pass to the
* function.
* @param {Function} [callback] - the final argument should be the callback,
* called when all functions have completed processing.
* @returns {AsyncFunction} - A function, that when called, is the result of
* appling the `args` to the list of functions. It takes no args, other than
* a callback.
* applying the `args` to the list of functions. It takes no args, other than
* an optional callback. If no callback is passed, it returns a Promise.
*/
export default applyEach(mapSeries);