pub const RATE_LIMITER: &str = "machine RateLimiter<K> {\r\n state Available(tokens: i64, max_tokens: i64)\r\n state Exhausted(retry_after_ms: i64, max_tokens: i64)\r\n\r\n transition acquire: Available -> Available | Exhausted\r\n transition refill: Exhausted -> Available\r\n\r\n effect now_ms() -> i64\r\n\r\n on acquire() {\r\n if tokens > 0 {\r\n goto Available(tokens - 1, max_tokens);\r\n } else {\r\n goto Exhausted(perform now_ms(), max_tokens);\r\n }\r\n }\r\n\r\n on refill() {\r\n goto Available(max_tokens, max_tokens);\r\n }\r\n}\r\n";Expand description
The Gust source for the RateLimiter machine.
A token-bucket rate limiter with two states:
- Available – tokens remain; requests can proceed.
- Exhausted – no tokens left; a
retry_after_msvalue indicates when tokens will be replenished.
Generic over K for the rate-limit key type.