SlidingWindowRateLimiter class
Allows at most limit events per trailing window (a half-open
(now - window, now] interval).
Constructors
-
SlidingWindowRateLimiter({required int limit, required Duration window, DateTime now()?})
-
Creates a limiter permitting
limit (≥ 1) events per window (> 0).
now supplies the current time (defaults to DateTime.now); tests pass a
virtual clock to advance time deterministically.
Audited: 2026-06-12 11:26 EDT
Properties
-
hashCode
→ int
-
The hash code for this object.
no setterinherited
-
limit
→ int
-
Maximum events permitted within any single trailing window.
final
-
runtimeType
→ Type
-
A representation of the runtime type of the object.
no setterinherited
-
window
→ Duration
-
The trailing window width.
final
Methods
-
currentCount()
→ int
-
The number of events currently inside the window (after pruning expired
ones).
Audited: 2026-06-12 11:26 EDT
-
noSuchMethod(Invocation invocation)
→ dynamic
-
Invoked when a nonexistent method or property is accessed.
inherited
-
timeUntilAvailable()
→ Duration
-
How long until the next event would be admitted, or Duration.zero if one
is admissible now. When at the limit, that is when the oldest in-window
event ages out (
oldest + window).
Audited: 2026-06-12 11:26 EDT
-
toString()
→ String
-
A string representation of this object.
override
-
tryAcquire()
→ bool
-
Tries to record one event now: returns true and logs it if fewer than
limit events fall in the current window, false otherwise (not logged).
Audited: 2026-06-12 11:26 EDT