Created
October 23, 2022 04:01
-
-
Save wktdev/3986430c6d078f1b75f9c6b5a90941f6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 App do | |
use GenServer | |
def start_link([]) do | |
GenServer.start_link(__MODULE__, []) | |
end | |
def init(state) do | |
{:ok, state} | |
end | |
def get_state(pid) do | |
GenServer.call(pid, :get_state) | |
end | |
def set_state(pid,state) do | |
GenServer.call(pid, {:set_state, state}) | |
end | |
def handle_call(:get_state, _from, state) do | |
{:reply, state, state} | |
end | |
def handle_call({:set_state, new_state}, _from, state)do | |
{:reply,state,[new_state | state]} | |
end | |
end | |
defmodule App.Supervisor do | |
use Supervisor | |
def start_link([])do | |
Supervisor.start_link(__MODULE__, []) | |
end | |
def init(_) do | |
children = [ | |
{App, []} | |
] | |
Supervisor.init(children, strategy: :one_for_one) | |
end | |
end | |
App.Supervisor.start_link([]) | |
{:ok, pid} = App.start_link([]) | |
Process.exit(pid, :kill) | |
pid = Process.whereis(App) | |
IO.inspect pid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.