Last active
March 30, 2022 03:48
-
-
Save jayhuang75/e46a224a78dc458037479eb1794af6a2 to your computer and use it in GitHub Desktop.
token_bucket_handle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub fn handle(&mut self, tokens: i64) { | |
| self.update(); | |
| if self.current_tokens >= tokens { | |
| self.current_tokens = self.current_tokens - tokens; | |
| self.forward(tokens); | |
| } else { | |
| self.queue(tokens); | |
| // for demo | |
| // after some time period | |
| // we reset the capacites | |
| self.current_tokens = self.max_tokens; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment