I’m having some difficulties to understand how one...
# android
j
I’m having some difficulties to understand how one can get an instance of a
FlowCollector
or anything build through the builder helpers function like
flow { }, callbackFlow { }, etc...
. What I want is to be able to do something like that from my fragment (or activity) but in a “correct” way
Copy code
private lateinit var collector: FlowCollector<MainFragmentEvent>

private val events = flow<MainFragmentEvent> {
    collector = this
}

override onResume() {
    lifecycleScope.launch {
        collector.emit(MainFragmentEvent.ResumeEvent(requireContext()))
    }
}
Can I do that only by using
Channel, SendChannel, etc...
and then convert it some how to a
Flow
?
z
This would be a great use case for the proposed
EventFlow
, but since that doesn't exist yet you can use
BroadcastChannel
, which has an
asFlow()
extension method.
n
j
it did not 😞 it’s not answering what I was asking.