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

voddan

11/29/2017, 11:11 AM
BTW, how do I limit the number of concurrent children my coroutine might have? The suggested way of using a limited thread pool can't be used as-is since I have to use the parent context to have the parent-child relationship.
Copy code
fun main(args: Array<String>) = runBlocking {
    (0..100).forEach { 
         launch(coroutineContext) {   // <- limit the number of concurrent threads ?
             mySuspendingTask() 
         } 
    }
}
e

elizarov

11/29/2017, 1:32 PM
launching coroutines could not and should not suspend. The “worker pool” pattern works the other way around. You launch a fixed number of coroutines and then they all together produce the same channel.
👍 1
3 Views