Skip to content

Commit

Permalink
Use MainLoopDispatcher on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline committed Oct 26, 2018
1 parent aceb86b commit 3615c42
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/iosMain/kotlin/example/GitHubIos.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
package example

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Runnable
import platform.Foundation.NSRunLoop
import platform.Foundation.performBlock
import kotlin.coroutines.CoroutineContext

actual fun <T> runBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T {
return kotlinx.coroutines.runBlocking(context, block)
return kotlinx.coroutines.runBlocking(MainLoopDispatcher, block)
}

// https://github.com/Kotlin/kotlinx.coroutines/issues/470#issuecomment-414635811
object MainLoopDispatcher: CoroutineDispatcher() {
override fun dispatch(context: CoroutineContext, block: Runnable) {
NSRunLoop.mainRunLoop().performBlock {
block.run()
}
}
}

0 comments on commit 3615c42

Please sign in to comment.