Import std.time.timers
RateLimiter
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))-
countevery per, with a bucket ofcounttokens, or of burst, which panics for a count,per, or burst that isn't above 0. -
counttokens everyper, with a bucket ofburst, which panics for a count,per, orburstthat isn't above 0. -
Takes a token, now or at the Instant, when there is one, and gives whether it did.
-
Takes a token at
nowwhen 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. -
How long it is, from now or the Instant, until there's a token to take.
-
How long it is from
nowuntil there's a token to take. -
Takes a token, sleeping until there's one.
Report an issue with this page or with FutureBlitz on GitHub.