https://kotlinlang.org logo
#coroutines
Title
# coroutines
k

Klara Erlebachova

11/05/2019, 5:09 PM
Hi, is there any way to use
runBlocking
with K/N? I used it in my MPP project for synchronous API and works fine on Android but on iOS it never returns. Even very simple example like this:
Copy code
val result = runBlocking(MainDispatcher) {
            return@runBlocking "yes"
        }
I found issue which is kinda related but there is no answer: https://github.com/Kotlin/kotlinx.coroutines/issues/952
l

louiscad

11/06/2019, 8:25 AM
Just use
runBlocking
without specifying a dispatcher.
It'll use the thread being blocked as an event loop. Beware, waiting for callbacks on that same thread will result in a deadlock.
Maybe you just need to use
launch
with the dispatcher from this comment? https://github.com/Kotlin/kotlinx.coroutines/issues/470#issuecomment-440080970
3 Views