拿到顺序执行多个promise的请求结果
所有接口都执行完毕后的回调
就是排队执行
async function executeSequentially() {
const promises = [fetchData1(), fetchData2(), fetchData3()];
for (const promise of promises) {
await promise;
}
// 在这里执行你的函数
yourFunction();
}
// 假设这是三个网络请求的函数
function fetchData1() {
return fetch('/api/data1').then(response => response.json());
}
function fetchData2() {
return fetch('/api/data2').then(response => response.json());
}
function fetchData3() {
return fetch('/api/data3').then(response => response.json());
}
// 你的函数
function yourFunction() {
console.log('All promises have been executed sequentially.');
}
// 调用函数
executeSequentially();