how to combine two `SharedFlow`s into `Flow` that ...
# coroutines
m
how to combine two `SharedFlow`s into
Flow
that emits when either
SharedFlow
emits?
f
Use flow.combine?
m
Copy code
Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.
if one flow doesn’t emit resulting flow won’t emit either right?
c
combine
is for grouping the results of multiple flows into a single object. To simply create a new Flow that passes through the individual emissions from each one independently,
merge
is the correct operator to use here
m
Copy code
suspend fun main() {
    val a = MutableSharedFlow<String>()
    val b = MutableSharedFlow<Int>()

    a.emit("")
    b.emit(1)

    merge(a, b)
        .collect { println(it) }
}
prints nothing @Casey Brooks. am I doing it wrong?
c
By default, `MutableSharedFlow`s will drop emissions if there are no subscribers. You'll need to start
collect { }
-ing before calling
.emit
on either of the original flows
2
m
riiiight, thanks!
840 Views