Sha256: 524ac44ed8e2f7f767d7ab197296dbb99e99c0497e99b22a296e36e881563168

Contents?: true

Size: 1.22 KB

Versions: 47

Compression:

Stored size: 1.22 KB

Contents

"use strict";
module.exports = function(
    Promise, INTERNAL, tryConvertToPromise, apiRejection) {
var util = require("./util");

var raceLater = function (promise) {
    return promise.then(function(array) {
        return race(array, promise);
    });
};

function race(promises, parent) {
    var maybePromise = tryConvertToPromise(promises);

    if (maybePromise instanceof Promise) {
        return raceLater(maybePromise);
    } else {
        promises = util.asArray(promises);
        if (promises === null)
            return apiRejection("expecting an array or an iterable object but got " + util.classString(promises));
    }

    var ret = new Promise(INTERNAL);
    if (parent !== undefined) {
        ret._propagateFrom(parent, 3);
    }
    var fulfill = ret._fulfill;
    var reject = ret._reject;
    for (var i = 0, len = promises.length; i < len; ++i) {
        var val = promises[i];

        if (val === undefined && !(i in promises)) {
            continue;
        }

        Promise.cast(val)._then(fulfill, reject, undefined, ret, null);
    }
    return ret;
}

Promise.race = function (promises) {
    return race(promises, undefined);
};

Promise.prototype.race = function () {
    return race(this, undefined);
};

};

Version data entries

47 entries across 43 versions & 15 rubygems

Version Path
optimacms-0.4.3 spec/dummy/node_modules/bluebird/js/release/race.js
optimacms-0.4.2 spec/dummy/node_modules/bluebird/js/release/race.js
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/bluebird/js/release/race.js
locomotivecms-3.4.0 app/javascript/node_modules/bluebird/js/release/race.js
cortex-0.1.3 spec/dummy/node_modules/bluebird/js/release/race.js
dragonfly_puppeteer-0.1.0 node_modules/bluebird/js/release/race.js
lanes-0.8.0 node_modules/bluebird/js/release/race.js