chore: no need for erlang:demonitor optimisation

This commit is contained in:
Zaiming (Stone) Shi 2022-04-08 15:51:59 +02:00
parent b0bbe32667
commit 2d374a3b0d
1 changed files with 2 additions and 15 deletions

View File

@ -72,23 +72,10 @@ demonitor(Pid, PMon = ?PMON(Map)) ->
PMon PMon
end. end.
%% @doc Improved version of erlang:demonitor(Ref, [flush]).
%% Only try to receive the 'DOWN' messages when it might have been sent.
-spec demonitor(reference()) -> ok. -spec demonitor(reference()) -> ok.
demonitor(Ref) when is_reference(Ref) -> demonitor(Ref) when is_reference(Ref) ->
case erlang:demonitor(Ref, [info]) of _ = erlang:demonitor(Ref, [flush]),
true -> ok.
%% succeeded
ok;
_ ->
%% '_', but not 'false' because this may change in the future according to OTP doc
receive
{'DOWN', Ref, process, _, _} ->
ok
after 0 ->
ok
end
end.
-spec find(pid(), pmon()) -> error | {ok, term()}. -spec find(pid(), pmon()) -> error | {ok, term()}.
find(Pid, ?PMON(Map)) -> find(Pid, ?PMON(Map)) ->