An open API service indexing awesome lists of open source software.

https://github.com/agrafix/ratelimiter

Haskell: In-memory rate limiter
https://github.com/agrafix/ratelimiter

Last synced: about 2 months ago
JSON representation

Haskell: In-memory rate limiter

Awesome Lists containing this project

README

          

# Haskell: ratelimiter

A simple in-memory rate-limiter library.

## Usage

``` haskell
import Control.RateLimiter
import qualified Data.Vector as V

main :: IO
main =
-- one rate limiter can have multiple rules
do limiter <-
newRateLimiter $ V.fromList
[ RateLimitConfig (RollingWindow 60) 200 -- 200 per minute
, RateLimitConfig (RollingWindow 3600) 400 -- 400 per hour
]
let myRateLimitedFunction =
do isLimited <- isRateLimited () limiter
if isLimitd then pure Nothing else Just <$> someExpensiveWork
-- ... use myRateLimitedFunction
```