Hi, I have a function that does a lengthy operation, but I want it to return only after this operation is completed. Also I would like the caller of the function to call it inside a coroutine because it could block them.
I did something like:
Copy code
suspend 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 PM
Screen Shot 2021-09-13 at 2.05.40 PM.png
Remon Shehata
09/13/2021, 12:11 PM
not sure how to handle the case I described above; make the function return after it has completed the operation and let the caller use coroutine. thoughts?
d
Didier Villevalois
09/13/2021, 12:21 PM
#coroutines would be a better fit for this question.
runBlocking
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