Merge pull request #7565 from zmstone/0408-fix-bad-optimisation

chore: no need for erlang:demonitor optimisation
This commit is contained in:
Zaiming (Stone) Shi 2022-04-08 21:40:01 +01:00 committed by GitHub
commit 64eccecede
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 15 deletions

View File

@ -72,23 +72,10 @@ demonitor(Pid, PMon = ?PMON(Map)) ->
PMon
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.
demonitor(Ref) when is_reference(Ref) ->
case erlang:demonitor(Ref, [info]) of
true ->
%% 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.
_ = erlang:demonitor(Ref, [flush]),
ok.
-spec find(pid(), pmon()) -> error | {ok, term()}.
find(Pid, ?PMON(Map)) ->