Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Last active March 30, 2022 03:48
Show Gist options
  • Select an option

  • Save jayhuang75/e46a224a78dc458037479eb1794af6a2 to your computer and use it in GitHub Desktop.

Select an option

Save jayhuang75/e46a224a78dc458037479eb1794af6a2 to your computer and use it in GitHub Desktop.
token_bucket_handle
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