lib/altshift/promise.js
function (array) {
            var self = this,
                deferred = new Deferred(),
                fulfilled = 0,
                length,
                results = [],
                hasError = false;

            if (!isArray(array)) {
                array = slice.call(arguments);
            }
            length = array.length;

            if (length === 0) {
                deferred.emitSuccess(results);
            } else {
                array.forEach(function (promise, index) {

                    self.when(promise,
                        //Success
                        function (value) {
                            results[index] = value;
                            fulfilled += 1;
                            if (fulfilled === length) {

                                if (hasError) {
                                    deferred.emitError(results);
                                } else {
                                    deferred.emitSuccess(results);
                                }
                            }
                        },
                        //Error
                        function (error) {
                            results[index] = error;
                            hasError = true;
                            fulfilled += 1;
                            if (fulfilled === length) {
                                deferred.emitError(results);
                            }
                        }
                    );
                });
            }
            return deferred.getPromise();
        }
function (array) {
            var self = this,
                deferred = new Deferred(),
                fulfilled = 0,
                length,
                results = [],
                hasError = false;

            if (!isArray(array)) {
                array = slice.call(arguments);
            }
            length = array.length;

            if (length === 0) {
                deferred.emitSuccess(results);
            } else {
                array.forEach(function (promise, index) {

                    self.when(promise,
                        //Success
                        function (value) {
                            results[index] = value;
                            fulfilled += 1;
                            if (fulfilled === length) {

                                if (hasError) {
                                    deferred.emitError(results);
                                } else {
                                    deferred.emitSuccess(results);
                                }
                            }
                        },
                        //Error
                        function (error) {
                            results[index] = error;
                            hasError = true;
                            fulfilled += 1;
                            if (fulfilled === length) {
                                deferred.emitError(results);
                            }
                        }
                    );
                });
            }
            return deferred.getPromise();
        }
function ( array ) { var self = this , deferred = new Deferred ( ) , fulfilled = 0 , length , results = [ ] , hasError = false ; if ( ! isArray ( array ) ) { array = slice . call ( arguments ) ; } length = array . length ; if ( length === 0 ) { deferred . emitSuccess ( results ) ; } else { array . forEach ( function ( promise , index ) { self . when ( promise , //Success function ( value ) { results [ index ] = value ; fulfilled += 1 ; if ( fulfilled === length ) { if ( hasError ) { deferred . emitError ( results ) ; } else { deferred . emitSuccess ( results ) ; } } } , //Error function ( error ) { results [ index ] = error ; hasError = true ; fulfilled += 1 ; if ( fulfilled === length ) { deferred . emitError ( results ) ; } } ) ; } ) ; } return deferred . getPromise ( ) ; }
Takes an array of promises and returns a promise that is fulfilled once all
the promises in the array are fulfilled

@param {Array} array The array of promises
@return {Promise} the promise that is fulfilled when all the array is fulfilled, resolved to the array of results
Takes an array of promises and returns a promise that is fulfilled once all the promises in the array are fulfilled