[erlang-questions] monitor/2

Tony Rogvall tony@REDACTED
Sun Mar 16 21:26:47 CET 2014


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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140316/e518e5f7/attachment.htm>


More information about the erlang-questions mailing list