Hi guys. What would be a good pattern to discard a...
# coroutines
u
Hi guys. What would be a good pattern to discard a pending (due to
debounce()
) value inside a `Flow`:
Copy code
val changesChannel: Channel<String>
val changes: Flow<String> = changesChannel.consumeAsFlow()
which is collected in the following manner:
Copy code
changes.debounce().map { saveChange(it) }.collect()
Due to some race condition, I need to prevent to save currently pending value (i.e. value that is scheduled to be persisted after debounce timeout). I could go by overwriting current value. For that, I would create:
Copy code
sealed class Change {
    /** 
     * Active change value
     */
    data class Active(val text: String) : Change()

    /**
     * Idle change value (value was previously cleared)
     */
    object Idle : Change()
}
Is there a better way to go? 🦄