Skip to content

Commit

Permalink
Flush unwanted timeout messages from gproc_pool:claim/3 (#192)
Browse files Browse the repository at this point in the history
Before this change a {claim, Pool} message is left in the caller's
mailbox for every timeout.
  • Loading branch information
leoliu authored Apr 24, 2023
1 parent 946cf5a commit 3856e76
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/gproc_pool.erl
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ execute_claim(F, K, Pid) ->
setup_wait(nowait, _) ->
nowait;
setup_wait({busy_wait, MS}, Pool) ->
Ref = erlang:send_after(MS, self(), {claim, Pool}),
Ref = erlang:start_timer(MS, self(), {claim, Pool}),
{busy_wait, Ref}.

do_wait(nowait) ->
Expand All @@ -569,7 +569,9 @@ do_wait({busy_wait, Ref} = W) ->
erlang:yield(),
case erlang:read_timer(Ref) of
false ->
erlang:cancel_timer(Ref),
receive {timeout, Ref, _} -> ok
after 0 -> ok
end,
timeout;
_ ->
W
Expand Down

0 comments on commit 3856e76

Please sign in to comment.