等待 Node.connect 后再使用:global.whereis_name

Wait for Node.connect before using :global.whereis_name

我有以下功能:

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

我收到错误:

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

我认为这是因为 Node.connect 收集了一些信息,当我调用 :global.whereis_name 时它还没有完成。如果我确实输入 :timer.sleep(1000) 就不会出错。有更优雅的解决方案吗?我想重复 :global.whereis_name 直到成功或超时。

编辑:

我应该提一下,我已经注册了一个名为 id 的节点。

你可以在 :global.whereis_name(id)

之前做一个 :global.sync()