rate_limiter library

Classes

BackOff<T>
Object holding options for retrying a function.
Debounce
Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked. The debounced function comes with a Debounce.cancel method to cancel delayed func invocations and a Debounce.flush method to immediately invoke them. Provide leading and/or trailing to indicate whether func should be invoked on the leading and/or trailing edge of the wait interval. The func is invoked with the last arguments provided to the call function. Subsequent calls to the debounced function return the result of the last func invocation.
Throttle
Creates a throttled function that only invokes func at most once per every wait milliseconds. The throttled function comes with a Throttle.cancel method to cancel delayed func invocations and a Throttle.flush method to immediately invoke them. Provide leading and/or trailing to indicate whether func should be invoked on the leading and/or trailing edge of the wait timeout. The func is invoked with the last arguments provided to the throttled function. Subsequent calls to the throttled function return the result of the last func invocation.

Extensions

BackOffExtension on FutureOr<T> Function()
Useful rate limiter extensions for Function class.
RateLimit on Function
Useful rate limiter extensions for Function class.

Functions

backOff<T>(FutureOr<T> func(), {Duration delayFactor = const Duration(milliseconds: 200), double randomizationFactor = 0.25, Duration maxDelay = const Duration(seconds: 30), int maxAttempts = 8, FutureOr<bool> retryIf(Object error, int attempt)?}) Future<T>
TopLevel lambda to apply BackOff to functions.
debounce(Function func, Duration wait, {bool leading = false, bool trailing = true, Duration? maxWait}) Debounce
TopLevel lambda to create Debounce functions.
throttle(Function func, Duration wait, {bool leading = true, bool trailing = true}) Throttle
TopLevel lambda to create Throttle functions.