Async/Await not working inside for loop for loop me in any case
v8.16.0 Ubuntu 18.04 LTS
Hi guys, I'm trying to fetch values from other server through my node.js code. I'm using for loop for this purpose and wanted to wait inside for loop to get value first then move to 2nd iteration and so on. For this I'm putting it in aync/await but failed as for loop not wait for the server result then iterate next. Is async/await works inside for loop????
Could you provide a minimal code that reproduces the issue?
async/await works inside for-loops. the problem probably lies in the code. If you ask a question it's recommended to post a code snippet with it so we can be helpful
I confirm. I have await function that do a call to Spotify API inside for of loop and it not wait. It's diffictult to provide minimal example. Node version 14.15.4
Works perfectly fine for Node v14.15.4 LTS
const asyncTimeout =(timeout)=> new Promise(res => setTimeout(res, timeout));
main();
async function main() {
for (let counter = 0; counter < 10; counter++) {
await asyncTimeout(1000);
console.log(`${counter}: ${new Date().toISOString()}`);
}
}
So there must be an error in the code with which we can only help if you provide a minimal example.
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
This bug still exists as far as I can see...