Skip to content

Commit 416b25e

Browse files
committed
Unify duplicated function
1 parent ed1ea3d commit 416b25e

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

src/throttle/amoc_throttle_controller.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
ensure_throttle_processes_started/2,
1212
pause/1, resume/1, stop/1, get_info/1,
1313
change_rate/2, change_rate_gradually/2,
14-
pg_scope/0,
14+
pg_scope/0, consume_all_messages/1,
1515
get_throttle_process/1,
1616
raise_event_on_slave_node/2, telemetry_event/2]).
1717

@@ -260,16 +260,16 @@ continue_plan(Name, State, Info, #change_rate_plan{rates = [Rate]} = Plan) ->
260260
TRef = Plan#change_rate_plan.timer,
261261
Info1 = do_change_rate(Name, Rate, Interval, Info),
262262
{ok, cancel} = timer:cancel(TRef),
263-
consume_all_timer_ticks({change_plan, Name}),
263+
consume_all_messages({change_plan, Name}),
264264
State#{Name => Info1#throttle_info{change_plan = undefined}};
265265
continue_plan(Name, State, Info, #change_rate_plan{rates = [Rate | Rates]} = Plan) ->
266266
Info1 = do_change_rate(Name, Rate, Info#throttle_info.interval, Info),
267267
NewPlan = Plan#change_rate_plan{rates = Rates},
268268
State#{Name => Info1#throttle_info{change_plan = NewPlan}}.
269269

270-
consume_all_timer_ticks(Msg) ->
270+
consume_all_messages(Msg) ->
271271
receive
272-
Msg -> consume_all_timer_ticks(Msg)
272+
Msg -> consume_all_messages(Msg)
273273
after 0 -> ok
274274
end.
275275

src/throttle/amoc_throttle_process.erl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,13 @@ maybe_stop_timer(#state{tref = undefined}) ->
143143
ok;
144144
maybe_stop_timer(#state{tref = TRef}) ->
145145
{ok, cancel} = timer:cancel(TRef),
146-
consume_all_timer_ticks(delay_between_executions).
146+
amoc_throttle_controller:consume_all_messages(delay_between_executions).
147147

148148
timeout(#state{delay_between_executions = infinity}) ->
149149
infinity;
150150
timeout(#state{delay_between_executions = Delay}) ->
151151
Delay + ?DEFAULT_MSG_TIMEOUT.
152152

153-
consume_all_timer_ticks(Msg) ->
154-
receive
155-
Msg -> consume_all_timer_ticks(Msg)
156-
after 0 -> ok
157-
end.
158-
159153
maybe_run_fn(#state{schedule = [], schedule_reversed = []} = State) ->
160154
State;
161155
maybe_run_fn(#state{schedule = [], schedule_reversed = SchRev} = State) ->

0 commit comments

Comments
 (0)