【发布时间】:2019-10-24 14:11:20
【问题描述】:
我需要在一个 for 循环中启动许多协程,并在所有任务完成后在主线程中获取回调。
最好的方法是什么?
//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.
}
并且在 CoroutineScope 中没有迭代消息的变体。迭代必须在主线程中完成。
【问题讨论】:
标签: kotlin coroutine kotlin-coroutines