Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 84x 84x 39x 39x 45x 84x 2x 2x 2x 2x 2x | /**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
// MODULES //
var factory = require( './factory.js' );
// MAIN //
/**
* Invokes a function once for each element in a collection.
*
* ## Notes
*
* - If a provided function calls the callback with a truthy error argument, iteration stops and `done` is invoked.
* - This function is not guaranteed to be asynchronous. Use `setImmediate`, `setTimeout`, or `process.nextTick` to ensure async behavior.
*
* @param {Collection} collection - input collection
* @param {Options} [options] - function options
* @param {*} [options.thisArg] - execution context
* @param {PositiveInteger} [options.limit] - maximum concurrent invocations
* @param {boolean} [options.series=false] - process elements serially
* @param {Function} fcn - function to invoke for each element
* @param {Callback} done - function invoked upon completion
* @throws {TypeError} first argument must be a collection
* @throws {TypeError} options must be an object
* @throws {TypeError} `fcn` must be a function
* @throws {TypeError} `done` must be a function
* @returns {void}
*
* @example
* function done( error ) {
* if ( error ) {
* throw error;
* }
* console.log( 'Completed.' );
* }
*
* function process( value, next ) {
* setTimeout( function onTimeout() {
* console.log( 'Processed: %s', value );
* next();
* }, 10 );
* }
*
* var arr = [ 1, 2, 3 ];
*
* forEachAsync( arr, process, done );
*/
function forEachAsync( collection, options, fcn, done ) {
if ( arguments.length < 4 ) {
return factory( options )( collection, fcn );
}
factory( options, fcn )( collection, done );
}
// EXPORTS //
module.exports = forEachAsync;
|