image.png
// 封装请求的接口(接口不可用)
function logAfter3s(id) {
return new Promise((resolve, reject) => {
axios.get(`https://test.com/get?id=${id}`).then(res => {
resolve(res)
}).catch(error => {
console.log(error)
})
})
}
//一轮10次并发请求
async function fn1() {
return new Promise((resolve, reject) => {
for (let i = 0; i < 10; i++) {
try {
logAfter3s(i).then(res=>{resolve(res)});
if (i === 10) return;
} catch (e) {
console.log(e);
}
}
})
}
//分20轮一次依次发出
async function fn2() {
let aa
for (let i = 0; i <= 20; i++) {
aa = await fn1()
}
}
网友评论