Whats the best way to download multiple files in coroutines with a fixed amount of parallel download...
j
Whats the best way to download multiple files in coroutines with a fixed amount of parallel downloads. So there are like 1000 files and I want to download them in parallel but only 4 at a time
t
You probably want to take a look at coroutines Semaphore. You could also create 4 "download file" actors and fan out using channels.
j
Yep. Channel + repeat(4) { launch{ download() } }. Shove all 1000 URLs into the channel.
☝️ 1
c
or use a channel of 4 for throttling
y
This won't stop them all being started at once. Just stop the CPU intensive bits from running concurrently. The network bits will happily go 1000 at once.
402 Views