CLOVIS
06/03/2025, 9:48 AMsuspend fun doSomething() = coroutineScope {
val data1 = async { fetchData1() }
val data2 = async { fetchData2() }
val data3 = async { fetchData3() }
doSomething(data1.await(), data2.await(), data3.await())
}
Is there a way to declare that this function should use high parallelism when it's latency-critical, and use parallelism only if the system is idle? We don't want to simply reduce the parallelism of non-critical operations, because if the system is doing few things, having high parallelism for these operations is still beneficial.
Maybe some kind of priority? Maybe with another dispatcher?Sam
06/03/2025, 10:06 AMDmitry Khalanskiy [JB]
06/03/2025, 10:13 AMcoroutineContext
has a special "urgent operation" marker).CLOVIS
06/03/2025, 11:01 AMlouiscad
06/03/2025, 11:35 AMDispatchers.Default.limitedParallelism
and/or differentiated use of yield()
in between CPU intensive loops could help you do thatCLOVIS
06/03/2025, 12:08 PMDispatchers.Default.lowPriority
louiscad
06/03/2025, 12:30 PMlouiscad
06/03/2025, 12:31 PMCLOVIS
06/03/2025, 12:55 PMUli Bubenheimer
06/03/2025, 12:58 PMlouiscad
06/03/2025, 1:03 PMlouiscad
06/03/2025, 1:03 PMCLOVIS
06/03/2025, 1:03 PMlouiscad
06/03/2025, 5:01 PMThread.currentThread().priority = something
CLOVIS
06/04/2025, 8:39 AMlouiscad
06/04/2025, 9:03 AM