lib/promise.js
function when(args, cb, eb) {
    var p;
    args = argsToArray(arguments);
    eb = base.isFunction(args[args.length - 1]) ? args.pop() : null;
    cb = base.isFunction(args[args.length - 1]) ? args.pop() : null;
    if (eb && !cb) {
        cb = eb;
        eb = null;
    }
    if (!args.length) {
        p = new Promise().callback(args);
    } else if (args.length === 1) {
        args = args.pop();
        if (isPromiseLike(args)) {
            p = args;
        } else if (isArray(args) && array.every(args, isPromiseLike)) {
            p = new PromiseList(args, true);
        } else {
            p = new Promise().callback(args);
        }
    } else {
        p = new PromiseList(args.map(function (a) {
            return isPromiseLike(a) ? a : new Promise().callback(a);
        }), true);
    }
    if (cb) {
        p.addCallback(cb);
    }
    if (eb) {
        p.addErrback(eb);
    }
    return p.promise();

}
function when(args, cb, eb) {
    var p;
    args = argsToArray(arguments);
    eb = base.isFunction(args[args.length - 1]) ? args.pop() : null;
    cb = base.isFunction(args[args.length - 1]) ? args.pop() : null;
    if (eb && !cb) {
        cb = eb;
        eb = null;
    }
    if (!args.length) {
        p = new Promise().callback(args);
    } else if (args.length === 1) {
        args = args.pop();
        if (isPromiseLike(args)) {
            p = args;
        } else if (isArray(args) && array.every(args, isPromiseLike)) {
            p = new PromiseList(args, true);
        } else {
            p = new Promise().callback(args);
        }
    } else {
        p = new PromiseList(args.map(function (a) {
            return isPromiseLike(a) ? a : new Promise().callback(a);
        }), true);
    }
    if (cb) {
        p.addCallback(cb);
    }
    if (eb) {
        p.addErrback(eb);
    }
    return p.promise();

}
function when ( args , cb , eb ) { var p ; args = argsToArray ( arguments ) ; eb = base . isFunction ( args [ args . length - 1 ] ) ? args . pop ( ) : null ; cb = base . isFunction ( args [ args . length - 1 ] ) ? args . pop ( ) : null ; if ( eb && ! cb ) { cb = eb ; eb = null ; } if ( ! args . length ) { p = new Promise ( ) . callback ( args ) ; } else if ( args . length === 1 ) { args = args . pop ( ) ; if ( isPromiseLike ( args ) ) { p = args ; } else if ( isArray ( args ) && array . every ( args , isPromiseLike ) ) { p = new PromiseList ( args , true ) ; } else { p = new Promise ( ) . callback ( args ) ; } } else { p = new PromiseList ( args . map ( function ( a ) { return isPromiseLike ( a ) ? a : new Promise ( ) . callback ( a ) ; } ) , true ) ; } if ( cb ) { p . addCallback ( cb ) ; } if ( eb ) { p . addErrback ( eb ) ; } return p . promise ( ) ; }
Waits for promise and non promise values to resolve and fires callback or errback appropriately. If you pass in an array of promises
then it will wait for all promises in the list to resolve.

@example
var a = "hello";
var b = new comb.Promise().callback(world);
comb.when(a, b) => called back with ["hello", "world"];

@param {Anything...} args variable number of arguments to wait for.
@param {Function} cb the callback function
@param {Function} eb the errback function
@returns {comb.Promise} a promise that is fired when all values have resolved
@static
@memberOf comb
Waits for promise and non promise values to resolve and fires callback or errback appropriately . If you pass in an array of promises then it will wait for all promises in the list to resolve .