nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
token_bucket.h
Go to the documentation of this file.
1#ifndef NANOMMO_SERVER_TOKEN_BUCKET_H_
2#define NANOMMO_SERVER_TOKEN_BUCKET_H_
3
4#include <chrono>
5
6namespace nanommo {
7
8/// Lets up to `size` through at once, and then one each `refill`, like a
9/// bucket of tokens that fills up again over time, where each one let through
10/// takes a token out.
12 public:
13 TokenBucket(int size, std::chrono::steady_clock::duration refill);
14
15 /// Takes a token out, if the bucket has one at this time.
16 bool Take(std::chrono::steady_clock::time_point now);
17
18 private:
19 int size_;
20 std::chrono::steady_clock::duration refill_;
21 double tokens_;
22 std::chrono::steady_clock::time_point last_;
23};
24
25} // namespace nanommo
26
27#endif // NANOMMO_SERVER_TOKEN_BUCKET_H_
TokenBucket(int size, std::chrono::steady_clock::duration refill)
bool Take(std::chrono::steady_clock::time_point now)
Takes a token out, if the bucket has one at this time.
Definition chat.cc:9