Skip to main content
15 events
when toggle format what by license comment
Feb 4, 2024 at 13:02 history edited user3413723 CC BY-SA 4.0
added 34 characters in body
Dec 9, 2023 at 22:44 comment added dsschneidermann I count myself a javascript expert among other things, and looked at this code like ^_- Well done! Today I learned why Array.entries() is way more powerful than Object.entries.
Aug 26, 2023 at 20:38 comment added snobb @user3413723 BTW - I generally don't like the forEach function, because for-loop is better almost in every case (better performance, etc). It would make sense if it was async, but it's not. I played around with your code but refactored the the forEach with a recursive async loop instead - no wasted array allocation and more control but it's too tiny optimisation to be significant. here are my tests on the subject: gist.github.com/snobb/80822d895646222e789adb5b5bf11c4b
Aug 25, 2023 at 19:53 comment added user3413723 @Alex I actually spent a lot of time trying to understand how this works after I read Endless answer. Live and learn! Thanks for responding, I always like to hear what people think about my comments! :)
Aug 25, 2023 at 14:56 comment added snobb @user3413723 Thanks and sorry, looks like I've misread the code and was incorrect on both accounts. Indeed the code should work for limited concurrency - I missed the fact that the limited concurrency is powered by iterators. It's very clever - TIL.
Aug 24, 2023 at 12:40 comment added user3413723 @Alex take a look at the code again. Note that I am doing an async forEach on an array of 5 items - this represents worker count. In the loop, you'll notice that there is an asynchronous fetch, so the forEach has to be async in order to allow that. The code is confusing, but the async is so that each of the workers can do async tasks. The "magic" is that each for loop is iterating over the same cursor! But that's how iterators work, different loops can iterate the same cursor "at the same time"-obviously not really but close enough with the event loop (if you don't know what that is google)
Aug 24, 2023 at 7:58 comment added snobb in NodeJS .forEAch is not async aware so the code above is not necessary safe and should not be used with async code. Please read the following document on the subject: zellwk.com/blog/async-await-in-loops The code in the answer can be rewritten using regular for-loops though without changing the logic. IMHO the answer does not answer the question though - it does not mention limited concurrency - in other words the proposed code will process all the tasks concurrently, while the question is how to process at most N tasks in parallel. It takes more effort to achieve.
Dec 11, 2022 at 20:48 history edited user3413723 CC BY-SA 4.0
deleted 120 characters in body
Dec 11, 2022 at 19:10 history edited user3413723 CC BY-SA 4.0
added 293 characters in body
Dec 6, 2022 at 22:45 comment added Chunky Chunk Thank you for offering an answer that doesn't immediately rely on some unnecessary, bloated library.
Mar 28, 2022 at 9:26 history edited Endless CC BY-SA 4.0
updated the snippet to something that actually works
Oct 3, 2020 at 18:48 comment added Kristian Oye Curious as to why this got marked down. It is very similar to what I came up with.
May 4, 2020 at 14:43 history edited user3413723 CC BY-SA 4.0
Apr 27, 2020 at 14:37 history edited user3413723 CC BY-SA 4.0
added 459 characters in body
Mar 10, 2020 at 16:44 history answered user3413723 CC BY-SA 4.0