https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
h

Hauke Radtki

12/13/2018, 1:01 PM
Can someone head me in the right direction using the expect/actual mechanism to have a CoroutineDispatcher (MainThread/singleThread/UI) that works on Andorid, iOS and in tests on a plain JVM? If I integrate the solution presented here: https://github.com/Kotlin/kotlinx.coroutines/issues/470#issuecomment-440080970 I'm unable to provide an actual implementation for the jvm target
e

elizarov

12/14/2018, 2:38 PM
In common code:
Copy code
expect val MainDispatcher: CoroutineDispatcher
In JVM code:
Copy code
actual val MainDispatcher: CoroutineDispatcher get() = Dispatchers.Main
In iOS code:
Copy code
actual val MainDispatcher: CoroutineDispatcher get() = MainLoopDispatcher // from that solution
h

Hauke Radtki

12/14/2018, 4:05 PM
My mistake was that I was trying to expect/actual an object instead of a val. Thanks! 👍