Promise.race 实现原理

Promise.prototype.race = function(promises) {
    return new Promise((resolve, reject) => {
        if (!isArray(promises)) {
            return reject(new TypeError('Arguments not Array'));
        }
        for (let p of promises) {
            Promise.resolve(p).then(
                res => resolve(res), 
                rej => reject(rej)
            )
        }
    })
}

Last updated