@commercial/items v2.2.0
items
Bare minimum async methods adapted specifically for the very limited hapi core use cases. Use async for all your application needs.
License
This version of the package requires a commercial license. You may not use, copy, or distribute it without first acquiring a commercial license from Sideway Inc. Using this software without a license is a violation of US and international law. To obtain a license, please contact sales@sideway.com. The open source version of this package can be found here.
Usage
Items.serial(items, method, callback)
Runs method against each value in the items array in series. callback is executed when all of the tasks are complete. Calling back with an error will short-circuit the remaining tasks.
itemsan array of items to pass tomethod.methoda function with the signaturefunction (item, next, i).item- is the currently processing item in theitemsarray.next- callback function to indicate the end of processing foritem. Callingnextwith a truthy parameter indicates an error and endsItems.serial.i- The current item's index in theitemsarray.
callback- a function with the signaturefunction (err).err- indicates any errors during processing.
Items.parallel(items, method, callback)
Runs method against each value in the items array in parallel. callback is executed when all of the tasks are complete. Calling back with an error will short-circuit the remaining tasks.
itemsan array of items to pass tomethod.methoda function with the signaturefunction (item, next, i).item- is the currently processing item in theitemsarray.next- callback function to indicate the end of processing foritem. Callingnextwith a truthy parameter indicates an error and endsItems.parallel.i- The current item's index in theitemsarray.
callback- a function with the signaturefunction (err).err- indicates any errors during processing.
Items.parallel.execute(tasks, callback)
Runs all of the functions in tasks in parallel and stores the results in a collector object passed into callback. If any of the tasks callback with an error, the collector object is null.
tasks- on object containing functions to execute in parallel. Thekeyof the function is thekeyin the result of collector object. The task should have the signaturefunction (next)next(err, result)- callback function to indicate the end of processing for the current task.err- indicates any errors during processing.result- result of this function. This value will be set on the collector object in the final callback.
callback(err, result)err- any errors reported by any of thetasks.result- an object containing the result of running all of thetasks.resultwill benullif any of the tasks callback with an error. Theresult.keywill be the correspondingkeyof thetasksobject.
7 years ago