rkeazor
02/22/2020, 9:15 PMAdam Powell
02/22/2020, 9:15 PMBroadcastChannel<T>.asFlow()
?rkeazor
02/22/2020, 9:17 PMAdam Powell
02/22/2020, 9:17 PMrkeazor
02/22/2020, 9:18 PMlouiscad
02/23/2020, 1:47 AMrkeazor
02/23/2020, 3:59 PMBrendan Weinstein
02/23/2020, 5:31 PMclass EventProducer(private val channel: BroadcastChannel<Event>) :
SendChannel<Event> by channel
class EventConsumer(private val channel: BroadcastChannel<Event>) :
Flow<Event> by channel.asFlow()
Brendan Weinstein
02/23/2020, 5:32 PMclass FlowRelay<T>(capacity: Int) : Flow<T> {
@InternalCoroutinesApi
override suspend fun collect(collector: FlowCollector<T>) {
flow.collect(collector)
}
@UseExperimental(ExperimentalCoroutinesApi::class)
private val broadcastChannel = BroadcastChannel<T>(capacity)
@UseExperimental(FlowPreview::class)
private val flow: Flow<T> = broadcastChannel.asFlow()
@UseExperimental(ExperimentalCoroutinesApi::class)
suspend fun send(event: T) {
broadcastChannel.send(event)
}
}
louiscad
02/24/2020, 8:03 AMEventConsumer
class is lying to what it actually is, plus it's pointless, you can just use asFlow
and keep a reference to it, your binary will end up smaller, and your code simpler.Brendan Weinstein
02/25/2020, 10:35 PM