magnumrocha
05/23/2021, 7:28 PMConflatedBroadcastChannel(Unit)
using the StateFlow
or SharedFlow
?
my first try is with a MutableStateFlow<Boolean>(false)
and every time I have a change in my logic that dispatch a signal, I do: myflow.value = !myflow.value
, but this looks weird 😅Erik
05/23/2021, 7:47 PMMutableSharedFlow<Unit>(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
and immediately emit Unit
. Not sure if really equivalent, but it should be able to emit the same value multiple times and emitters should never suspend/fail.magnumrocha
05/23/2021, 7:49 PMursus
05/26/2021, 12:38 PMErik
05/26/2021, 1:20 PMUnit
and there always is 1 value, then peeking makes no sense 😉magnumrocha
05/26/2021, 1:22 PMConflatedBroadcastChannel(Unit)
just as a trigger to notify about some event… this is a easy approach, and StateFlow<Unit>
will not work….Erik
05/26/2021, 1:23 PMmagnumrocha
05/26/2021, 1:23 PMursus
05/26/2021, 5:02 PMmagnumrocha
08/02/2021, 8:41 PMMutableSharedFlow<Unit>(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
behaviours like a StateFlow
So, I’ve created an object like:
sealed class BaseTriggerEvent {
override fun equals(other: Any?): Boolean = false
override fun hashCode(): Int = kotlin.random.Random.nextInt()
}
object TriggerEvent: BaseTriggerEvent()
That never will be equals the same object, so I can use like:
private val refreshTrigger = MutableStateFlow(TriggerEvent)
magnumrocha
08/02/2021, 8:43 PM