https://kotlinlang.org logo
Title
j

jean

05/12/2020, 2:32 PM
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
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

Zach Klippenstein (he/him) [MOD]

05/12/2020, 3:47 PM
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

Nikhil Mule

05/12/2020, 10:17 PM
j

jean

05/13/2020, 5:44 AM
it did not 😞 it’s not answering what I was asking.