I need to start many coroutines in a for loop and get a callback in the Main thread after all the tasks are completed.
What is the best way to do this?
//Main thread
fun foo(){
messageRepo.getMessages().forEach {message->
GlobalScope.launch {
doHardWork(message)
}
}
// here I need some callback to the Main thread that all work is done.
}
And there is no variant to iterate messages in CoroutineScope. The iteration must be done in the Main thread.