手写 Promise.all
Promise.myAll = function (list) {
const results = [];
let count = 0;
return new Promise((resolve, reject) => {
list.map((promise, index) => {
promise.then(
(r) => {
results[index] = r;
count += 1;
if (count === list.length) {
resolve(results);
}
},
(reason) => {
reject(reason);
}
);
});
});
};Last updated