EventTransformer

sealed class EventTransformer

Controls how a new event of the same type is handled while a previous handler is still active or pending.

Attach a transformer when registering a handler in a Bloc:

on<SearchEvent.Query>(transformer = EventTransformer.Debounce(300.milliseconds)) { event, emit ->
performSearch(event.query, emit)
}
TransformerBehaviourBest for
SequentialDefault. Processes events one at a time in order.Counters, toggles
ConcurrentEach event gets its own coroutine, all run in parallel.Independent fire-and-forget ops
DroppableIgnores new events while the previous handler coroutine is active.Expensive one-shot ops
RestartableCancels the running handler and starts fresh with the new event."Load latest" patterns
DebounceWaits for a quiet period; each new event resets the timer.Live search
ThrottleFires immediately, then ignores events for the duration.Scroll-triggered pagination

Inheritors

Types

Link copied to clipboard

Run each event handler in its own coroutine concurrently.

Link copied to clipboard
data class Debounce(val duration: Duration) : EventTransformer

Wait for duration of silence before invoking the handler. Each new event resets the countdown. The handler is called only once after the quiet period expires.

Link copied to clipboard

Silently drop incoming events while a previous handler coroutine is still running. The first event fires immediately; duplicates are discarded until the job completes.

Link copied to clipboard

Cancel the currently running handler coroutine and start a fresh one for the new event. Ideal for "fetch latest" patterns where only the most recent request matters.

Link copied to clipboard

Process events one at a time in arrival order. This is the default.

Link copied to clipboard
data class Throttle(val duration: Duration) : EventTransformer

Invoke the handler immediately for the first event, then suppress further events for duration.