1 #include "hmbdc/Copyright.hpp" 4 #include "hmbdc/Exception.hpp" 5 #include "hmbdc/time/Time.hpp" 10 namespace hmbdc {
namespace time {
11 using namespace hmbdc;
22 Rater(
Duration duration,
size_t times,
size_t burst,
bool enabled =
true)
23 : drop_(duration / (times?times:1ul))
24 , bucket_(drop_ * burst)
25 , currentLevel_(bucket_)
27 , enabled_(enabled?times != 0:
false)
30 bool check(
size_t n = 1u) {
31 if (!enabled_)
return true;
33 auto now = SysTime::now();
34 currentLevel_ += now - previousCheck_;
36 if (currentLevel_ > bucket_) currentLevel_ = bucket_;
37 return currentLevel_ >= drop_ * n;
41 currentLevel_ -= drop_ * n_;
Definition: Client.hpp:11