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
- Host: GitHub
- URL: https://github.com/agrafix/ratelimiter
- Owner: agrafix
- License: bsd-3-clause
- Created: 2020-12-21T04:28:21.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-12-21T04:45:48.000Z (over 5 years ago)
- Last Synced: 2025-12-08T11:47:44.057Z (6 months ago)
- Language: Haskell
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```