João Gabriel Zó
08/16/2023, 1:06 PMflosch
08/16/2023, 1:08 PMJoão Gabriel Zó
08/16/2023, 1:40 PMawaitAll
on a list would be enough.CLOVIS
08/16/2023, 2:06 PMawaitAll
works.
If you want to have a maximum number of parallel operations (e.g. to avoid spamming a server too much), I recommend using Arrow : documentation • parMap • sourceCasey Brooks
08/16/2023, 2:14 PMuli
08/16/2023, 2:28 PMCasey Brooks
08/16/2023, 2:31 PMlimitedParallelism
, and other things do is limit the number of active Coroutines. While not strictly limiting the number of active threads, it does limit how many API calls are being run concurrently, which eases the load on the server just the sameuli
08/16/2023, 2:35 PMparMap
. If I get it right, it limits the “operations”, not the threads, right @CLOVISuli
08/16/2023, 2:37 PMparMap
CLOVIS
08/16/2023, 2:41 PMYou can also limit parallelism with the DispatcherThat's quite a lot more costly than what Arrow is doing
rather than bringing in all of Arrow for that one featureIf you really do not use anything else, you can probably just copy the contents of the methods, it's just the `map`→`async` method with a
Semaphore
. But honestly, Arrow FX is very lightweight, I would still use the libraryCLOVIS
08/16/2023, 2:42 PMWhile not strictly limiting the number of active threads, it does limit how many API calls are being run concurrently, which eases the load on the server just the sameActually, it's much more performant, because
Semaphore
doesn't imply context switching, whereas using a custom dispatcher does.
Also, it works even on platforms where threads don't exist, e.g. JavaScriptJoão Gabriel Zó
08/16/2023, 5:15 PMCLOVIS
08/17/2023, 7:27 AMparMap
and parZip
, and nothing else, is really not a big deal, and you can start using other things as the team grows more familiar with it.CLOVIS
08/17/2023, 7:28 AMCLOVIS
08/17/2023, 7:29 AM