Tian Tian098
05/28/2025, 5:59 PMFlow.buffer
function, which got a decent result
files.asFlow()
.map { async { download(it) } }
.buffer(CONCURRENCY)
.collect { it.await() }
But this runs all the operations in order. In particular, if operation 1 takes really long, and the rest of the operations in the buffer are done, then I won't start any new operations until operation 1 is done.
Is there a better way?ephemient
05/28/2025, 6:09 PMfiles.asFlow()
.flatMapMerge(CONCURRENCY) {
flow {
download(it)
}
}
.collect()
Tian Tian098
05/28/2025, 6:26 PMdebop
05/29/2025, 5:43 AMrenatomrcosta
05/29/2025, 7:26 AMefemoney
05/31/2025, 7:56 AMval dispatcher = Dispatcher.IO[or Default or Whatever].limitedParallelism(CONCURRENCY)
files.map {
async(dispatcher) {
download(it)
}
}.awaitAll()
as thats the direct equivalent of what you explained
(this is important because there is a proliferation of unnecessary flow operations in the wild which are modelled better as just simple routines)