[英]Kotlin Flow - is there anything similar to LiveData's emitSource?
我有一個 function 參數 function 返回一個流,
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可以這樣發送的?
如果您想從 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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.