elaborate tissue

11/07/2019, 2:28 PM
Need help with what dispatchers i'm supposed to use.. So far I tried:
runBlocking {
            launch (Dispatchers.Unconfined) {
                // check every x seconds if file exists, if it does then kill app (and all other coroutines)
            launch (<http://Dispatchers.IO|Dispatchers.IO>) {
                // every x seconds send metrics to server
            for (i in 1..Runtime.getRuntime().availableProcessors()) {
                launch (Dispatchers.Default) {
                    // use remaining cpu/mem resources to process batch items
running this means that when all available processors are doing work, the jobs which are supposed to run every x seconds never run, how am I supposed to get them to run regularly regardless of if available processors are performing the batch work?


11/07/2019, 5:00 PM
You need to design your coroutine usage to be cooperative
IIRC default dispatchers is already based on CPU availability so you're actually limiting your batch processors there
Also, for your batch work, you'll want to bake in some calls to
or other suspension points that way it give a chance for other coroutines to run
if your batch work is never taking a break you're effectively pegging the cpu and not allowing other work to be done
coroutines are not magic, you must think about threading still