Try to add a certain amount of resources consumed to a key. Return `true` if the key was within limits, `false` if it needs to wait. The [`RateLimit`] is passed in so that we can update it dynamically based on how much data we anticipate we will have to serve.
(&mut self, limit: &RateLimit, key: K, cost: u32)
| 30 | /// The [`RateLimit`] is passed in so that we can update it dynamically |
| 31 | /// based on how much data we anticipate we will have to serve. |
| 32 | pub fn add(&mut self, limit: &RateLimit, key: K, cost: u32) -> bool { |
| 33 | self.add_at(limit, key, cost, Instant::now()) |
| 34 | } |
| 35 | |
| 36 | /// Same as [`RateLimiter::add`] but allows passing in the time, for testing. |
| 37 | pub fn add_at(&mut self, limit: &RateLimit, key: K, cost: u32, at: Instant) -> bool { |
no test coverage detected