js/lib/utilities.js
function (arr, handler) {
        var tmp = when.defer();
        var index = -1;
        var results = [];

        var doNext = function () {
            try {
                index++;

                if (index > arr.length) {
                    tmp.resolve(results);
                }

                var file = arr[index];
                var promise = handler(file);
                if (promise) {
                    when(promise).then(function (result) {
                        results.push(result);
                        process.nextTick(doNext);
                    }, function () {
                        process.nextTick(doNext);
                    });
//                    when(promise).ensure(function () {
//                        process.nextTick(doNext);
//                    });
                }
                else {
                    //logger.log('skipping bad promise');
                    process.nextTick(doNext);
                }
            }
            catch (ex) {
                logger.error("pdas error: " + ex);
            }
        };

        process.nextTick(doNext);

        return tmp.promise;
    }
function (arr, handler) {
        var tmp = when.defer();
        var index = -1;
        var results = [];

        var doNext = function () {
            try {
                index++;

                if (index > arr.length) {
                    tmp.resolve(results);
                }

                var file = arr[index];
                var promise = handler(file);
                if (promise) {
                    when(promise).then(function (result) {
                        results.push(result);
                        process.nextTick(doNext);
                    }, function () {
                        process.nextTick(doNext);
                    });
//                    when(promise).ensure(function () {
//                        process.nextTick(doNext);
//                    });
                }
                else {
                    //logger.log('skipping bad promise');
                    process.nextTick(doNext);
                }
            }
            catch (ex) {
                logger.error("pdas error: " + ex);
            }
        };

        process.nextTick(doNext);

        return tmp.promise;
    }
function ( arr , handler ) { var tmp = when . defer ( ) ; var index = - 1 ; var results = [ ] ; var doNext = function ( ) { try { index ++ ; if ( index > arr . length ) { tmp . resolve ( results ) ; } var file = arr [ index ] ; var promise = handler ( file ) ; if ( promise ) { when ( promise ) . then ( function ( result ) { results . push ( result ) ; process . nextTick ( doNext ) ; } , function ( ) { process . nextTick ( doNext ) ; } ) ; //                    when(promise).ensure(function () { //                        process.nextTick(doNext); //                    }); } else { //logger.log('skipping bad promise'); process . nextTick ( doNext ) ; } } catch ( ex ) { logger . error ( "pdas error: " + ex ) ; } } ; process . nextTick ( doNext ) ; return tmp . promise ; }
handle an array of stuff, in order, and don't stop if something fails.
@param arr
@param handler
@returns {promise|*|Function|Promise|when.promise}
handle an array of stuff in order and don t stop if something fails .