Created
August 10, 2015 03:08
-
-
Save zabirauf/c250a7c6799b20f79303 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule EphemeralShare.PeerState do | |
require Logger | |
use GenServer | |
def start_link(peer_id) do | |
GenServer.start_link(__MODULE__, [peer_id], [name: {:global, peer_state_proc_id(peer_id)}]) | |
end | |
def stop(peer_id) do | |
peer_id | |
|> peer_state_proc_id | |
|> :global.whereis_name | |
|> GenServer.cast(:shutdown) | |
end | |
def peer_state_proc_id(peer_id) do | |
"peer_state:" <> peer_id | |
end | |
# Server (callbacks) | |
def init(args) do | |
{:ok, args} | |
end | |
def handle_cast(:shutdown, _from, state) do | |
Logger.debug "Shutdown peer state #{inspect(state)}" | |
{:stop, :shutdown, state} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment