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)
}
}
}
}
Rohan Maity
04/13/2023, 2:12 PM
I am using
runBlocking
because this functions result need to be used in Java file
d
Dmitry Khalanskiy [JB]
04/13/2023, 2:15 PM
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
Rohan Maity
04/13/2023, 2:16 PM
Ok. the callback functions does mention something about handling on UI thread
Now it makes sense