I have a function that runs on the Android main thread (UI thread):
fun someFunc() {
...
doSomething1()
doSomething2()
doSomething3()
...
}
I want to run doSomething2() asynchronously in a background thread and make sure that someFunc() is suspended (not blocked) until this execution completes. Once done, someFunc() should resume in the main thread (from doSomething3()). During this background thread execution, I want to make sure that main thread is free and not blocked.
I know this can be done using Futures, but I'm wondering how to do this using coroutines/async?