https://kotlinlang.org logo
Title
t

trathschlag

03/01/2018, 2:52 PM
Assumed I have an infinite source of tasks, for example some
ReceiveChannel
which lazily produces work and I want to schedule these on
CommonPool
. I can't just take every task from the source, because there are infinite. What's a good way to assure that for example always 1000 tasks are currently in my thread pool?
e

elizarov

03/01/2018, 6:30 PM
Smth like this:
repeat(1000) {
     launch(CommonPool) { 
         for (task in channel) {
             // process task
         }
     }
}
👍 3
t

trathschlag

03/02/2018, 10:14 AM
Nice, this is super easy! Thanks