https://kotlinlang.org logo
#coroutines
Title
# coroutines
r

rkeazor

06/04/2020, 2:55 PM
Can StateFlow represent one off events?
🚫 1
z

Zach Klippenstein (he/him) [MOD]

06/04/2020, 2:59 PM
It's not ideal if you're only emitting events (use
SharedFlow
for that). But if you're trying to express a one-off event in your state, you can use some kind of event ID to distinguish events over time.
s

streetsofboston

06/04/2020, 2:59 PM
You can finagle them to make that happen, but they are not ideal for this.
Until the SharedFlow become available, I wrapped a BroadcastChannel in a Flow to make my own shared-flow for now. It works, but the new SharedFlow is much more performant and not as ‘expensive’ (it doesn’t use a broadcastchannel, iirc).
✔️ 1
r

rkeazor

06/04/2020, 3:08 PM
Cool thanks yall
2 Views