I have a Boolean method inside that some nested method, I want to return that boolean value after completion of all methods but it first executes that boolean value and returns that. It prints->Entered, completed and started, end.
fun syncAll(): Boolean {
Log.d(TAG, "syncAll: Entered")
val job= Coroutines.io {
Log.d(TAG, "syncAll: started")
method1()
method2()
method3()
Log.d(TAG, "syncAll: end")
}
Log.d(TAG, "syncAll: completed")
return job.isCompleted
}
You need to make
syncAll()suspendfunction and call it fromCoroutineScopethat is at the calling site.Inside
syncAll()you can usewithContext()to await result from different methods running on different coroutine(s).