这不可能再简单了,但我不能理解这里的问题是什么.以下是我的代码:
fun main() {
val flow = flowOf(1, 2, 3)
CoroutineScope(Dispatchers.Default).launch {
println("Launch working")
flow.collect {
println("Collect: $it")
}
}
}
上面的代码不打印任何内容,甚至连"启动工作"都不打印.我甚至try 使用我自己的CoroutineScope
,如以下代码所示:
fun main() {
val flow = flowOf(1, 2, 3)
val myCoroutineScope = CoroutineScope(
CoroutineName("myCoroutineScope")
)
myCoroutineScope.launch {
println("My coroutine scope working")
flow.collect {
println("Collect: $it")
}
}
}
再说一次,它什么也没打印,甚至连"我的协同程序范围工作"都没打印出来.
我错过了什么吗?