Promise.prototype.all = function (listPromise) {
if (!Array.isArray(listPromise)) {
throw new TypeError("the arguments should be an array");
}
return new Promise((resolve, reject) => {
try {
let resultList = [];
let len = listPromise.length;
for (var i = 0; i < len; i++) {
listPromise[i].then((res) => {
resultList.push(res);
if (resultList.length == len) {
resolve(resultList);
}
}, reject);
}
} catch (e) {
reject(error);
}
});
};
Promise all如何实现
最新推荐文章于 2024-01-29 16:19:35 发布