Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swarm stops to respond when try to find name #145

Open
wesleimp opened this issue Mar 18, 2021 · 0 comments
Open

Swarm stops to respond when try to find name #145

wesleimp opened this issue Mar 18, 2021 · 0 comments

Comments

@wesleimp
Copy link

If you try to run Swarm.whereis_name(name) while Swarm.register_name(name, Sup....) didn't finish yet, the application stops to respond.

defmodule MyDynamicSupervisor do
  use DynamicSupervisor

  # Initialization
  
  def register(name) do
    child_spec = %{
      id: MyActor,
      start: {MyActor, :start_link, [name]},
      restart: :transient
    }

    case DynamicSupervisor.start_child(__MODULE__, child_spec) do
      {:error, {:already_started, pid}} -> {:ok, pid}
      {:ok, pid} -> {:ok, pid}
    end
  end
end
defmodule MyActor do
  use GenServer

  def start_actor(name) do
    {:ok, pid} = Swarm.register_name(name, MyDynamicSupervisor, :register, [name])
  end

  def start_link(name) do
    GenServer.start_link(__MODULE__, name)
  end

  def init(name) do
    pid = Swarm.whereis_name(name) # At this moment, the application stops to respond
    {:ok, name}
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant