-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aceb86b
commit 3615c42
Showing
1 changed file
with
14 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |