wai-token-bucket-ratelimiter-0.1.0.1: A request rate limiting middleware using token buckets
Safe HaskellSafe-Inferred
LanguageGHC2021

Control.Concurrent.TokenBucket

Synopsis

Documentation

data Rate Source #

Rate represents token bucket parameters.

Constructors

Rate 

Fields

  • rateBurstAmount :: !Word64

    Maximum number of tokens that the token bucket can hold.

  • rateNanosPerToken :: !Word64

    Rate at which tokens are to be added to the bucket - expressed as time in nanoseconds after which a token is added.

Instances

Instances details
Show Rate Source # 
Instance details

Defined in Control.Concurrent.TokenBucket

Methods

showsPrec :: Int -> Rate -> ShowS #

show :: Rate -> String #

showList :: [Rate] -> ShowS #

Eq Rate Source # 
Instance details

Defined in Control.Concurrent.TokenBucket

Methods

(==) :: Rate -> Rate -> Bool #

(/=) :: Rate -> Rate -> Bool #

mkRate :: Word64 -> (Word64, Word64) -> Rate Source #

mkRate creates a Rate given the burst amount, and the number of operations (must be > 0) to allow per number of seconds given.

infRate :: Rate Source #

infRate creates a Rate whose limit can never be exceeded. Useful to never limit an operation.

newTokenBucket :: Rate -> IO TokenBucket Source #

newTokenBucket creates an initially full token bucket.

tryAllocateTokens :: TokenBucket -> Word64 -> Rate -> IO (Maybe Word64) Source #

'tryAllocate tb amount rate' attempts to allocate amount tokens from the given token bucket at the given rate. On success, it returns Nothing, and on failure it returns the minimum amount of time to wait in nanoseconds before the allocation can succeed.