Throttler class

Throttle a function: at most one call per duration window.

final clickGuard = Throttler(duration: Duration(seconds: 1));
ElevatedButton(onPressed: () => clickGuard.run(() => submit()));

Constructors

Throttler({required Duration duration})

Properties

duration → Duration
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → void
Reset the throttle clock so the next run is immediate.
run(void fn()) → bool
Run fn if enough time has passed since the last allowed call. Returns whether the call was executed.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited