[erlang-questions] Test code for global module does not work...

Bernard Duggan <>
Fri Mar 12 04:39:07 CET 2010


钱晓明 wrote:
> Hi, I use global module to test global name, but it does not work. This is
> the simple test code:
>   
By default a node won't just automatically know about every other node
on your network.  You need to suggest to one that it go looking for the
other with something like:

pong = net_adm:ping('').

(obviously substituting in your actual node name).
> [snip]
> By the way, the references say: *If Name is not a globally registered name,
> the calling function will exit with reason {badarg, {Name, Msg}}. *So If I
> want to process the failure rather than just exit with reason badarg, what
> should I do ? Use try ... catch? I want to register new process with that
> name when the send failed.
>   
Yep, try-catch is probably the way I would do it.  The other option is
to check for the registered name with global:whereis_name/1 first (but
depending on your setup that could allow for a race condition where a
name becomes unregistered between that call and the attempt to send to it).

Cheers,

Bernard




More information about the erlang-questions mailing list