0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Cancel timers async

Where it wasn't already async. To slightly improve performance.
This commit is contained in:
David Ansari 2024-04-11 15:26:23 +02:00 committed by Loïc Hoguin
parent 2531b26acf
commit fcab905eca
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
3 changed files with 3 additions and 3 deletions

View file

@ -93,7 +93,7 @@ handle_cast(_Msg, State) ->
-spec handle_info(any(), State) -> {noreply, State} when State::#state{}. -spec handle_info(any(), State) -> {noreply, State} when State::#state{}.
handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef0}) -> handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef0}) ->
%% Cancel the timer in case an external process sent an update message. %% Cancel the timer in case an external process sent an update message.
_ = erlang:cancel_timer(TRef0), _ = erlang:cancel_timer(TRef0, [{async, true}, {info, false}]),
T = erlang:universaltime(), T = erlang:universaltime(),
B2 = update_rfc1123(B1, Prev, T), B2 = update_rfc1123(B1, Prev, T),
ets:insert(?MODULE, {rfc1123, B2}), ets:insert(?MODULE, {rfc1123, B2}),

View file

@ -328,7 +328,7 @@ cancel_timeout(State=#state{timer=TimerRef}) ->
_ -> _ ->
%% Do a synchronous cancel and remove the message if any %% Do a synchronous cancel and remove the message if any
%% to avoid receiving stray messages. %% to avoid receiving stray messages.
_ = erlang:cancel_timer(TimerRef), _ = erlang:cancel_timer(TimerRef, [{async, false}, {info, false}]),
receive receive
{timeout, TimerRef, _} -> ok {timeout, TimerRef, _} -> ok
after 0 -> after 0 ->

View file

@ -391,7 +391,7 @@ set_idle_timeout(State=#state{opts=Opts, timeout_ref=PrevRef}, TimeoutNum) ->
%% options are changed dynamically. %% options are changed dynamically.
_ = case PrevRef of _ = case PrevRef of
undefined -> ignore; undefined -> ignore;
PrevRef -> erlang:cancel_timer(PrevRef) PrevRef -> erlang:cancel_timer(PrevRef, [{async, true}, {info, false}])
end, end,
case maps:get(idle_timeout, Opts, 60000) of case maps:get(idle_timeout, Opts, 60000) of
infinity -> infinity ->