debounce<Event> function
Debounce: waits duration of silence after the last event, then processes
the most recent one.
Optionally compose with another transformer via andThen:
debounce(300.ms, andThen: droppable()) // debounce → droppable
debounce(300.ms) // standalone (sequential map)
Implementation
EventTransformer<Event> debounce<Event>(
Duration duration, {
EventTransformer<Event>? andThen,
}) {
return (events, mapper) {
final debounced = events.transform(_DebounceStreamTransformer(duration));
// If a downstream transformer is provided, pipe the debounced stream into
// it so the caller controls concurrency (droppable, restartable, …).
// Otherwise fall back to sequential (asyncExpand).
return andThen != null ? andThen(debounced, mapper) : debounced.asyncExpand(mapper);
};
}