【发布时间】:2022-12-03 16:11:24
【问题描述】:
我怎样才能让下面的流量收集器收到“你好”?收集器正在调用myFunction1(),后者又调用myFunction2()。两者都是暂停功能。
目前,当我点击运行时没有任何反应,也没有收到任何流量。我在这里错过了什么吗?
CoroutineScope(IO).launch {
val flowCollector = repo.myFunction1()
.onEach { string ->
Log.d("flow received: ", string)
}
.launchIn(GlobalScope)
}
class Repo {
suspend fun myFunction1(): Flow<String> = flow {
/*some code*/
myFunction2()
}
suspend fun myFunction2(): Flow<String> = flow {
/*some code*/
emit("hello")
}
}
【问题讨论】:
标签: kotlin kotlin-coroutines coroutine kotlin-flow suspend