Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait for Node.connect before using :global.whereis_name

Tags:

erlang

elixir

I have the following function:

  def join(id) do
    if Node.connect(:"#{id}@127.0.0.1") do
      send :global.whereis_name(id), {:join, id}
    end
  end

I receive the error:

(ArgumentError) argument error
               :erlang.send(:undefined, ...

which I assume is because Node.connect does some gathering of information and when I call :global.whereis_name it has not finished yet. If I throw in a :timer.sleep(1000) sure enough I don't get an error. Is there a more elegant solution? I would like repeat :global.whereis_name until successful or a timeout is reached.

EDIT:

I should mention that I already have a node registered with the name id.

like image 308
arynhard Avatar asked May 30 '15 23:05

arynhard


1 Answers

You could do a :global.sync() before :global.whereis_name(id)

like image 51
Kabie Avatar answered Sep 19 '22 11:09

Kabie