Pablo
12/08/2022, 10:03 AMfun longJobFunction(): MutableList<BigData>{
var bigDataList = mutableStateListOf<BigData>()
CoroutineScope(Dispatchers.Main).launch {
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
//fill bigDataList with big data
Thread.sleep(5000)
}
}
return bigDataList
}
But it gives this exception java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core'
John O'Reilly
12/08/2022, 10:32 AMJohn O'Reilly
12/08/2022, 10:32 AM// hack to allow use of MainScope() in shared code used by JVM console app
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:${Versions.kotlinCoroutines}")
Pablo
12/08/2022, 10:42 AMPablo
12/08/2022, 10:44 AMKevin S
12/08/2022, 1:58 PMimplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version")
in commonMain and
``implementation("org.jetbrains.kotlinxkotlinx coroutines android$version")`
in androidMain. Then I use viewModelScope
in androidMain and a MainScope
in iOS when launching from a ViewModel