async function getValue(x) {
await new Promise(r => setTimeout(r, 100)); // wait 100 ms
return x * 2;
}
const promises = [];
promises.push(getValue(1));
promises.push(getValue(2));
promises.push(getValue(3));
// right now, promises is an array of promises -- let's turn that into values:
(async () => {
const promiseValues = await Promise.all(promises);
console.log('values:');
console.log(promiseValues);
})();
将promise类型的数组转化为普通数组
最新推荐文章于 2023-05-04 03:51:23 发布