throttle method
BlocThrottleCallback<BlocEvent>
throttle(
- BlocThrottleCallback<
BlocEvent> function, { - Duration duration = const Duration(milliseconds: 300),
Creates a throttled function that only invokes function
at most once
per every duration
.
For example:
final throttled = throttle(() {
// heavy stuff
});
Implementation
BlocThrottleCallback throttle(
BlocThrottleCallback function, {
Duration duration = const Duration(milliseconds: 300),
}) {
final throttler =
PublishSubject<Tuple2<Function, Map<dynamic, dynamic>?>>();
publishers.add(throttler);
subxList.add(
throttler.throttleTime(duration).listen(
(Tuple2<Function, Map<dynamic, dynamic>?> tuple) {
tuple.item1(tuple.item2);
},
),
);
return ([Map<dynamic, dynamic>? extras]) {
final tuple = Tuple2<Function, Map<dynamic, dynamic>?>(function, extras);
throttler.add(tuple);
};
}