admin管理员组文章数量:1335854
Currently I am using Promise.all() to send multiple axios requests all at once, but I want to send the requests one by one, meaning send the second request after the first one pletes.
This is important so far as they timestamp of the POST request is important. The POST request for the promise in the 0th element of the array needs to have a earlier timestamp than the promise at the 1st element and so forth.
Here is the code I have written so far.
Promise.all(
rowNodes.map((row) => {
axios.post(url, row, axiosOptions);
})
)
.then((responseArr) => {
console.log(responseArr);
})
.catch((errorArr) => {
console.log(errorArr);
});
Currently I am using Promise.all() to send multiple axios requests all at once, but I want to send the requests one by one, meaning send the second request after the first one pletes.
This is important so far as they timestamp of the POST request is important. The POST request for the promise in the 0th element of the array needs to have a earlier timestamp than the promise at the 1st element and so forth.
Here is the code I have written so far.
Promise.all(
rowNodes.map((row) => {
axios.post(url, row, axiosOptions);
})
)
.then((responseArr) => {
console.log(responseArr);
})
.catch((errorArr) => {
console.log(errorArr);
});
Share
Improve this question
asked Nov 16, 2020 at 8:06
dracarysdracarys
1,1212 gold badges16 silver badges39 bronze badges
1
- See this post: Reading requests in sequence – Reyno Commented Nov 16, 2020 at 8:10
1 Answer
Reset to default 6Please try to use for
loop inside async/await
function. Like below
const someFunc = async () => {
...
const responses = [];
for (let i = 0; i < rowNodes.length; i++) {
responses.push(await axios.post(url, rowNodes[i], axiosOptions));
}
...
}
本文标签: javascriptSend multiple axios requests in a for loop in series (One after the other)Stack Overflow
版权声明:本文标题:javascript - Send multiple axios requests in a for loop in series (One after the other) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742397602a2467239.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论