Looking for an advice on limiting concurrency. My ...
# coroutines
e
Looking for an advice on limiting concurrency. My problem is that I want to limit parallel running coroutines per some token(user, credentials, whatever) created on demand. Current implementation works, but not sure about it: https://gist.github.com/enleur/4bdd04b0e2c54b94f84a2ca62ca9b6ac
d
Did you see this https://github.com/Kotlin/kotlinx.coroutines/commits/typed-actors ? It might give you some good ideas. Your implementation is similar, but simpler...
👍 1
Also, why have Pool implement CoroutineScope and not Dispatcher... the`coroutineScope` builder function inherits its job anyways, and you can change the dispatcher with
launch(<http://Dispatchers.IO|Dispatchers.IO>)
from the pool... that way you can cancel the whole Dispatcher class with all the workers, you could also make it a supervisor scope if you don't want one failing subtask to cancel its parent...
👍 1
e
Thanks! I'll look closer to TypedActors implementation
g
We really need worker pool implementation on kotlinx.coroutines. Vote for this issue and share your usecases https://github.com/Kotlin/kotlinx.coroutines/issues/172