Kotlin Flow - 有没有类似于 LiveData 的 emitSource 的东西?

Kotlin Flow - is there anything similar to LiveData's emitSource?

我有一个函数接受一个返回 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

   ...
   }

请问有什么可以让流量可以这样发送的吗?

如果你想从流中发出所有项目,这正是 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)
}