Would buffered flows be the current best way of fa...
# coroutines
Would buffered flows be the current best way of fanning out a number of (comparatively) long running http requests and aggregating the results?
How would a buffered flow do that? I woulnd’t use a flow at all. Just launch them all with
, and
all those after they’ve all been launched:
Copy code
val responses = listOf<Request>()
    .map { async { it.exec() } } // launch each HTTP request in parallel
    .map { it.await() } // wait for the responses to come in
Yeah I just realised it wouldn';t it would just buffer slow collectors
Alternatively, pushing the requests into a Channel and setting up “worker” coroutines to pull from that channel with a select expression can give you more control over the level of parallelism you want. Probably would want to push the results into another channel to aggregate them all https://kotlinlang.org/docs/select-expression.html
Channels would provide better support for cancellation if I wanted to do a "fail fast" type scenario where I wanted to cancel everything if one failed