Is there a way to cap the concurrency with corouti...
# coroutines
a
Is there a way to cap the concurrency with coroutines? when I run a lot of
async { ... http request ... }
at some point I am hitting connection refused, because the other end can not keep up.
v
If you are using
suspend
-based http-client (Ktor or any adapter around existing async clients), then there is no built-in solution and limiting threads count won’t help. https://github.com/Kotlin/kotlinx.coroutines/issues/460 may help, feel free to vote for it. As ad-hoc solution you can use suspend-based Semaphore (it was posted in a thread above)
Also, actors around worker pool (https://github.com/Kotlin/kotlinx.coroutines/issues/172) can help, but it’s also yet to be implemented 😞