Skip to content

Commit f2f51f6

Browse files
committed
refine rate_limiter
1 parent f731a0e commit f2f51f6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

include/ylt/coro_io/rate_limiter.hpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class abstract_smooth_rate_limiter : public rate_limiter {
7272
protected:
7373
virtual void do_set_rate(double permits_per_second,
7474
double stable_internal_micros) = 0;
75-
virtual long stored_permits_to_wait_time(double stored_permits,
76-
double permits_to_take) = 0;
75+
virtual std::chrono::milliseconds stored_permits_to_wait_time(
76+
double stored_permits, double permits_to_take) = 0;
7777
virtual double cool_down_internal_micros() = 0;
7878
void resync(std::chrono::steady_clock::time_point now_micros) {
7979
// if next_free_ticket is in the past, resync to now
@@ -110,10 +110,11 @@ class abstract_smooth_rate_limiter : public rate_limiter {
110110
double stored_permits_to_spend =
111111
std::min((double)required_permits, this->stored_permits_);
112112
double fresh_permits = required_permits - stored_permits_to_spend;
113-
std::chrono::milliseconds wait_micros = std::chrono::milliseconds(
113+
std::chrono::milliseconds wait_micros =
114114
stored_permits_to_wait_time(this->stored_permits_,
115115
stored_permits_to_spend) +
116-
(long)(fresh_permits * this->stable_internal_micros_));
116+
std::chrono::milliseconds(
117+
(long)(fresh_permits * this->stable_internal_micros_));
117118
this->next_free_ticket_micros_ += wait_micros;
118119
this->stored_permits_ -= stored_permits_to_spend;
119120
return return_value;
@@ -159,9 +160,9 @@ class smooth_bursty_rate_limiter : public abstract_smooth_rate_limiter {
159160
<< ", stored_permits_:" << this->stored_permits_;
160161
}
161162

162-
long stored_permits_to_wait_time(double stored_permits,
163-
double permits_to_take) {
164-
return 0L;
163+
std::chrono::milliseconds stored_permits_to_wait_time(
164+
double stored_permits, double permits_to_take) {
165+
return std::chrono::milliseconds(0);
165166
}
166167

167168
double cool_down_internal_micros() { return this->stable_internal_micros_; }

0 commit comments

Comments
 (0)