使用axios的多个请求无需等待所有这些请求在数组列表中完成? [英] Multiple requests with axios without waiting for all of them to finish in an array list?
本文介绍了使用axios的多个请求无需等待所有这些请求在数组列表中完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
taskList.push(
const data = {
url: 'http://${requestUrl}?${argsString}',
headers: {
'Content-Type': 'application/octet-stream',
Authorization: signature //,
//'Content-Length': buffer.length
},
method: 'POST',
data: buffer
}
return axios(data)
)
try {
const data = await Promise.all(taskList)
const res = data.map(d => d.data)
console.log(res)
//ctx.state.data = res
} catch (e) {
console.log(e)
throw e
}
如何不等待所有请求完成,因为所有完成需要太长时间。如果任何请求完成,我打印出来,对用户来说会非常快。
How to do not wait all requests finish, because all finish needs too long time. If any request finish, I print it out, it will be very fast for users.
推荐答案
如果每个响应都应该被记录一旦完成,它应该是:
In case each response should be logged as soon as it's completed, it should be:
const responses = await Promise.all(taskList.map(async task => {
const { data } = await task;
console.log(data);
return data;
}));
这篇关于使用axios的多个请求无需等待所有这些请求在数组列表中完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文