index.js
function when(promises) {
	promises = arrayify(promises);
	var whenPromise = new PromiseFactory();

	var pending = promises.length;
	var results = [];

	var resolve = function (i) {
		return function (val) {
			results[i] = val;
			pending--;

			if (pending === 0) {
				whenPromise.resolve(results);
			}
		};
	};

	promises.forEach(function (p, i) {
		if (!p || !p.then) return;

		p.then(resolve(i), whenPromise.reject);
	});

	return whenPromise.promise();
}
function when(promises) {
	promises = arrayify(promises);
	var whenPromise = new PromiseFactory();

	var pending = promises.length;
	var results = [];

	var resolve = function (i) {
		return function (val) {
			results[i] = val;
			pending--;

			if (pending === 0) {
				whenPromise.resolve(results);
			}
		};
	};

	promises.forEach(function (p, i) {
		if (!p || !p.then) return;

		p.then(resolve(i), whenPromise.reject);
	});

	return whenPromise.promise();
}
function when ( promises ) { promises = arrayify ( promises ) ; var whenPromise = new PromiseFactory ( ) ; var pending = promises . length ; var results = [ ] ; var resolve = function ( i ) { return function ( val ) { results [ i ] = val ; pending -- ; if ( pending === 0 ) { whenPromise . resolve ( results ) ; } } ; } ; promises . forEach ( function ( p , i ) { if ( ! p || ! p . then ) return ; p . then ( resolve ( i ) , whenPromise . reject ) ; } ) ; return whenPromise . promise ( ) ; }
Aggregates an array of promises into one promise which is resolved
when every constituent promise is resolved or rejected when some
constituent promise is rejected
@param  {Promise|Array.<Promise>} promises
@return {Promise}
Aggregates an array of promises into one promise which is resolved when every constituent promise is resolved or rejected when some constituent promise is rejected