Ah man, great points, all three! I went and edited to address (1) and (2). Depending on the example you're talking about with (3) above, that was more or less my point - running a bunch of awaited calls in a loop is sequential for better or worse.
Agile Full Stack Software Engineer with extended experience in Business Intelligence. I am a passionate coder, expressing my creativity through elegant code.
Sorry about the previous comment but I was replying from my mobile phone.
My point is that I would rewrite your third example like this:
constpostIds=['1','2','3','4','5'];asyncfunctionloadCommentsSequentially(ids){for(letidofpostIds){// wait for comments to be loaded and then load the comments from the next postreturnawaitloadComments(id);}}loadPostsSequentially().then((comments)=>...)
so that your next paragraph would make more sense:
There's a catch here, though - the await keyword will stop execution of the loop until loadComments returns for each post.
because in your example, using the forEach loop, the execution is not sequential, but rather a list of promises are created and are "lost" (nobody waits for them to be completed).
Ah man, great points, all three! I went and edited to address (1) and (2). Depending on the example you're talking about with (3) above, that was more or less my point - running a bunch of
await
ed calls in a loop is sequential for better or worse.Thanks for reading, I appreciate your insight!
Hello again,
nice article, really :)
Sorry about the previous comment but I was replying from my mobile phone.
My point is that I would rewrite your third example like this:
so that your next paragraph would make more sense:
because in your example, using the forEach loop, the execution is not sequential, but rather a list of promises are created and are "lost" (nobody waits for them to be completed).
I hope I explained it better this time :)
Ahhhh yeah, I see I see - yep, that makes sense! Thanks again Davide!