@Test
fun `test select flow`() = runBlocking<Unit> {
//函数 -》 Flow<协程> -> Flow合并
val name = "guest"
coroutineScope {
listOf(::getUserFromLocal, ::getUserFromLocal2).map { kFunction1 -> //遍历调用
//调用反射 需要添加依赖
// implementation 'org.jetbrains.kotlin:kotlin-reflect:1.7.0'
kFunction1.call(name)
}.map { deferred ->
flow { emit(deferred.await()) }
}.merge() //多个flow合并成一个flow
.collect { user -> //末端操作符
println(user)
}
}
}
Kotlin Flow实现多路复用
猜你喜欢
转载自blog.csdn.net/mp624183768/article/details/126799347
今日推荐
周排行