[erlang-questions] monitor/2

Anthony Ramine n.oxyde@REDACTED
Sun Mar 16 22:29:32 CET 2014


This sounds like a good idea but with many edge cases.

For starters, there lack a demonitor call with flush option set in the timeout clause.

Then, from what I understand reading your snippet of code, I gather that the message is only sent once, right?

What happens if I call monitor after the name was registered and wait for ‘UP’? Or will it wait for the process to die and the name to be freed to send a ‘DOWN’? In my opinion, this behaves in manner too different from process monitors to reuse the same function.

-- 
Anthony Ramine

Le 16 mars 2014 à 21:26, Tony Rogvall <tony@REDACTED> a écrit :

> 
> On 16 mar 2014, at 00:21, Tony Rogvall <tony@REDACTED> wrote:
> 
>> I would like to see (and have been for a long time :):
>> 
>> monitor(name, abc) -> reference()
>> 
>> and then be able get notifications when the name abc is registered and unregistered.
>> 
>> Then notifications could be something like:
>> 
>> {'UP',Ref, name, Pid, abc }
>> {'UP',Ref, name, Port, abc }
>> {'DOWN', Ref, name, Pid, abc}
>> {'DOWN', Ref, name, Port, abc}
>> 
> 
> A comment on my own suggestion:
> 
> The following (ugly) code in user_sup.erl:
> 
> wait_for_user_p(0) ->
>     {error, nouser};
> wait_for_user_p(N) ->
>     case whereis(user) of
> 	Pid when is_pid(Pid) ->
> 	    link(Pid),
> 	    {ok, Pid};
> 	_ ->
> 	    receive after 100 -> ok end,
> 	    wait_for_user_p(N-1)
>     end.
> 
> Could then be replace with:
> 
> wait_for_user_p(N) ->
> 	Timeout = N*100,
> 	Ref = erlang:monitor(name, user),
> 	recieve
> 		{'UP', Ref, name, Pid, user} ->
> 			link(Pid),
> 			{ok, Pid}
> 	after
> 		Timeout ->
> 			{error, nouser}
> 	end	.
> 
> 
>> /Tony
>> 
>> 
>> On 14 mar 2014, at 23:50, Loïc Hoguin <essen@REDACTED> wrote:
>> 
>>> Hello,
>>> 
>>> I want to discuss monitor/2.
>>> 
>>> It's been there for a while, and it's always taking 'process' as first argument. Any plans to add anything else? And if nothing is foreseen before the end of times, any plans to add a monitor/1 instead?
>>> 
>>> Thanks.
>>> 
>>> -- 
>>> Loïc Hoguin
>>> http://ninenines.eu
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions
>> 
>> "Installing applications can lead to corruption over time. Applications gradually write over each other's libraries, partial upgrades occur, user and system errors happen, and minute changes may be unnoticeable and difficult to fix"
>> 
>> 
>> 
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list