Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- data Rate = Rate {}
- mkRate :: Word64 -> (Word64, Word64) -> Rate
- infRate :: Rate
- data TokenBucket
- newTokenBucket :: Rate -> IO TokenBucket
- tryAllocateTokens :: TokenBucket -> Word64 -> Rate -> IO (Maybe Word64)
Documentation
Rate represents token bucket parameters.
Rate | |
|
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
creates a Rate
whose limit can never be exceeded. Useful to
never limit an operation.
data TokenBucket Source #
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.