I have a flow producer which emits continuously a ...
# coroutines
l
I have a flow producer which emits continuously a specific byte to represent an idle mode. I would like to drop these bytes but log them every 2 or 3 seconds. Any ideas how to achieve this?
d
What about the
sample
operator?
l
This would also filter the "good" bytes 😞 Thats says I'm also collecting useful bytes when not idling
e
Copy code
sealed class Mode {
    class Active : Mode() // Active() != Active()
    data class Idle(val unique: Long) : Mode()
}

.distinctUntilChangedBy { it ->
    if (isIdle(it)) Mode.Idle(System.currentTimeMillis() / 2500) else Mode.Active()
}
not as clever as
.sample()
but might be sufficient
l
Thanks guys