-
public interface StreamDebouncer<T extends Object>Debounces a bursty stream of values so that only the last value is delivered after a quiet period.
Each call to submit replaces the pending value and resets the delay timer. When the timer expires without a new submission, the registered onValue handler is invoked with the most recent value. This is useful for coalescing rapid state changes (network flaps, lifecycle transitions) into a single settled action.
Last-write-wins: Only the most recently submitted value is delivered.
Timer reset: Each submit cancels any pending delivery and restarts the delay.
Thread-safety: All functions are safe to call from multiple coroutines.
Cancellation:cancel discards the pending value and stops the timer without delivery.
-
-
Method Summary
Modifier and Type Method Description abstract UnitonValue(SuspendFunction1<T, Unit> callback)Registers the handler invoked when the debounce window elapses. abstract Unitsubmit(T value)Submits a new value, cancelling any pending delivery and restarting the delay timer. abstract Unitcancel()Cancels any pending delivery without invoking the handler. -
-
Method Detail
-
onValue
abstract Unit onValue(SuspendFunction1<T, Unit> callback)
Registers the handler invoked when the debounce window elapses.
- Parameters:
callback- Suspend function called with the settled value.
-
submit
abstract Unit submit(T value)
Submits a new value, cancelling any pending delivery and restarting the delay timer.
- Parameters:
value- The value to deliver after the debounce window.
-
-
-
-