Remon Shehata
09/13/2021, 12:09 PMsuspend fun foo(){
runBlocking(<http://Dispatchers.IO|Dispatchers.IO>) {
// do some operation and return only after it's completed
}
}
How ever adding the suspend modifier gave me the following warning (posted in reply).Remon Shehata
09/13/2021, 12:10 PMRemon Shehata
09/13/2021, 12:11 PMDidier Villevalois
09/13/2021, 12:21 PMrunBlocking
will block the current thread. Does the operation you do in place of your comment is a thread-blocking operation? If that is the case, I believe what you want to use is withContext(<http://Dispatchers.IO|Dispatchers.IO>) { ... }
. In what context do call your foo
method?
Also, the Coroutines guide is very helpful.Remon Shehata
09/13/2021, 12:31 PMwithContext(<http://Dispatchers.IO|Dispatchers.IO>) { ... }
then the function would return immediately. How I want it to return only when the operation is completed.
I call foo
from something like :`lifecycleScope.launch(Dispatachers.IO){foo}`Remon Shehata
09/13/2021, 12:32 PMRahul Gill
09/15/2021, 2:46 AM