throttle<Event> function Null safety

EventTransformer<Event> throttle<Event>(
  1. Duration duration,
  2. {bool trailing = false,
  3. bool leading = true}
)

Emits an , then ignores subsequent events for a duration, then repeats this process.

If leading is true, then the first event in each window is emitted. If trailing is true, then the last event is emitted instead.

Example

on<ExampleEvent>(
  _handler,
  transformer: throttle(const Duration(seconds: 5))
);

Implementation

EventTransformer<Event> throttle<Event>(
  Duration duration, {
  bool trailing = false,
  bool leading = true,
}) =>
    (events, mapper) => events
        .throttleTime(
          duration,
          trailing: trailing,
          leading: leading,
        )
        .switchMap(mapper);