https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

Albert

08/14/2018, 12:02 PM
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

Vsevolod Tolstopyatov [JB]

08/14/2018, 12:15 PM
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 😞
3 Views