我使用Promise.all
同时处理多个promise ,但我还需要 for each 已解析的promise 运行一个函数.我面临的问题是,如果我将函数直接传递给Promise的.Then(),它将立即执行,而不是等待Promise.all
触发它.如何在仍在使用Promise.All的同时 for each 已解析的promise 执行函数?我还需要了解这项计划的进展情况.
async function fetchData(url) {
/***
I want to append a callbackResolve for this fetch,
but if I use .then() it execute the function and not the Promise.all
**/
return await fetch(url);
}
const urls = [
'https://api.example.com/data1',
'https://api.example.com/data2',
'https://api.example.com/data3'
];
Promise.all(urls.map(fetchData))