Skip to content
FutureBlitz

    Install

    Import std.time.timers

    RateLimiter

    std.time.timers

    class

    Public Class RateLimiter

    Lets so many things happen in so long, as a bucket of that many tokens that refills one at a time, evenly, so a burst can take the bucket at once and then they go at the rate.

    Examples

    Local start = Instant.FromNanoseconds(0)
    Local limiter = RateLimiter(2, 1.Seconds)
    Expect(limiter.TryTake(start) && limiter.TryTake(start))
    Expect(!limiter.TryTake(start))
    Expect(limiter.TryTake(start + 500.Milliseconds))

    std/time/timers.fb, line 298

    • @PanicsAtCaller Public New(count: Int, per: Duration) constructor #

      count every per, with a bucket of count tokens, or of burst, which panics for a count, per, or burst that isn't above 0.

    • @PanicsAtCaller Public New(count: Int, per: Duration, burst: Int) constructor #

      count tokens every per, with a bucket of burst, which panics for a count, per, or burst that isn't above 0.

    • Public Method TryTake(): Bool method #

      Takes a token, now or at the Instant, when there is one, and gives whether it did.

    • Public Method TryTake(now: Instant): Bool method #

      Takes a token at now when there is one, and gives whether it did. A bucket that won't be full for longer than an Instant counts is full at the last one.

    • Public Method UntilNext(): Duration method #

      How long it is, from now or the Instant, until there's a token to take.

    • Public Method UntilNext(now: Instant): Duration method #

      How long it is from now until there's a token to take.

    • Public Method Take() method #

      Takes a token, sleeping until there's one.

    Report an issue with this page or with FutureBlitz on GitHub.