我有一个函数,它接受一个返回 Flow 的参数函数,
fun <T> resultFlow(
query: () -> Flow<T>,
... other parameters
): Flow<T> {
return flow {
val source = query()
//!!!! emit(source) // I want something like emitSource like livedata has
...
}
有没有什么可以让flow可以这样发送的?
最佳答案
如果你想从流中发出所有项目,这正是 emitAll()
做:
fun <T> resultFlow(
query: () -> Flow<T>,
... other parameters
): Flow<T> {
return flow {
val source = query()
// Note that this will suspend until all values from the flow are collected.
emitAll(source)
}
关于android - Kotlin Flow - 有没有类似于 LiveData 的 emitSource 的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68027567/