zeroTime_ = zeroTime;
}
+ /**
+ * Returns the current time in seconds since Epoch.
+ */
+ static double defaultClockNow() noexcept(noexcept(ClockT::timeSinceEpoch())) {
+ return std::chrono::duration_cast<std::chrono::duration<double>>(
+ ClockT::timeSinceEpoch())
+ .count();
+ }
+
/**
* Attempts to consume some number of tokens. Tokens are first added to the
* bucket based on the time elapsed since the last attempt to consume tokens.
return std::min((nowInSeconds - this->zeroTime_) * rate, burstSize);
}
- /**
- * Returns the current time in seconds since Epoch.
- */
- static double defaultClockNow() noexcept(noexcept(ClockT::timeSinceEpoch())) {
- return std::chrono::duration_cast<std::chrono::duration<double>>(
- ClockT::timeSinceEpoch())
- .count();
- }
-
private:
template <typename TCallback>
bool consumeImpl(
ParameterizedTokenBucket& operator=(
const ParameterizedTokenBucket& other) noexcept = default;
+ /**
+ * Returns the current time in seconds since Epoch.
+ */
+ static double defaultClockNow() noexcept(noexcept(Impl::defaultClockNow())) {
+ return Impl::defaultClockNow();
+ }
+
/**
* Change rate and burst size.
*
return burstSize_;
}
- /**
- * Returns the current time in seconds since Epoch.
- */
- static double defaultClockNow() noexcept(noexcept(Impl::defaultClockNow())) {
- return Impl::defaultClockNow();
- }
-
private:
Impl tokenBucket_;
double rate_;