如何实现 Promise.race
Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 314
Author 回答者: hwb2017
Promise.race = (promiseArray) => {
return new Promise((resolve, reject) => {
promiseArray.forEach((item) => {
Promise.resolve(item).then(
(val) => {
resolve(val);
},
(reason) => {
reject(reason);
},
);
});
});
};