lib/breakup.js
function() {
            // run iterator for this item
            iterator(arr[current], function(err) {
                // check for any errors with this element
                if (err) {
                    callback(err, yielded);
                } else {
                    // move onto the next element
                    current++;

                    if (current === arr.length) {
                        // all done
                        callback(null, yielded);
                    } else {
                        var now = +(new Date());

                        // check if we need to take a break at all
                        if (now > endTime) {
                            // reset start and end time
                            startTime = now;
                            endTime = startTime + workTime;

                            yielded = true;

                            // prioritize setImmediate
                            if (immediate) {
                                immediate(function() {
                                    iterate();
                                });
                            } else {
                                // if we're not doing an immediate yield, also add yield time
                                endTime += yieldTime;

                                setTimeout(function() {
                                    iterate();
                                }, yieldTime);
                            }
                        } else {
                            // work on the next item immediately
                            iterate();
                        }
                    }
                }
            });
        }
function() {
            // run iterator for this item
            iterator(arr[current], function(err) {
                // check for any errors with this element
                if (err) {
                    callback(err, yielded);
                } else {
                    // move onto the next element
                    current++;

                    if (current === arr.length) {
                        // all done
                        callback(null, yielded);
                    } else {
                        var now = +(new Date());

                        // check if we need to take a break at all
                        if (now > endTime) {
                            // reset start and end time
                            startTime = now;
                            endTime = startTime + workTime;

                            yielded = true;

                            // prioritize setImmediate
                            if (immediate) {
                                immediate(function() {
                                    iterate();
                                });
                            } else {
                                // if we're not doing an immediate yield, also add yield time
                                endTime += yieldTime;

                                setTimeout(function() {
                                    iterate();
                                }, yieldTime);
                            }
                        } else {
                            // work on the next item immediately
                            iterate();
                        }
                    }
                }
            });
        }
function ( ) { // run iterator for this item iterator ( arr [ current ] , function ( err ) { // check for any errors with this element if ( err ) { callback ( err , yielded ) ; } else { // move onto the next element current ++ ; if ( current === arr . length ) { // all done callback ( null , yielded ) ; } else { var now = + ( new Date ( ) ) ; // check if we need to take a break at all if ( now > endTime ) { // reset start and end time startTime = now ; endTime = startTime + workTime ; yielded = true ; // prioritize setImmediate if ( immediate ) { immediate ( function ( ) { iterate ( ) ; } ) ; } else { // if we're not doing an immediate yield, also add yield time endTime += yieldTime ; setTimeout ( function ( ) { iterate ( ) ; } , yieldTime ) ; } } else { // work on the next item immediately iterate ( ) ; } } } } ) ; }
Iteration loop function. Called once for each element
Iteration loop function . Called once for each element