I have converted callback to suspend function usin...
# coroutines
r
I have converted callback to suspend function using suspendCoroutine This suspend function works with
viewModelScope, CoroutineScope implemented by the class
but it does not work with
runBlocking
Whenever I call this suspend function
runBlocking
on main thread callback never returns But with other scopes it does Has someone faced this situation where suspend callback never returns value
Copy code
suspend fun suspendCallbackFun() : Boolean {
    return suspendCoroutine { 
        actualCallbackFunction { error ->
            if (error != null) {
                // Does not come here with runBlocking {}
                it.resume(false)
            }else {
                // Does not come here with runBlocking {}
                it.resume(true)
            }
        }
    }
}
I am using
runBlocking
because this functions result need to be used in Java file
d
runBlocking
blocks the thread it runs on until the block in it completes. So, the main thread can't do anything while this callback is awaited. Maybe this callback needs something to happen on the main thread, leading to a deadlock.
r
Ok. the callback functions does mention something about handling on UI thread Now it makes sense