Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defmodule First do
- use GenServer
- def start_link() do
- GenServer.start_link(__MODULE__, %{}, name: __MODULE__)
- end
- def init(state) do
- {:ok, Map.put(state, :process_list, [])}
- end
- def handle_call({:start_second, name}, _from, state) do
- process_list = Map.get(state, :process_list)
- {:ok, pid} = SecondProcess.start(name)
- {:ok, Map.put(state, :process_list, [{name, pid}|process_list])}
- {:reply, reply, state1}
- end
- def handle_call(_msg, _from, state) do
- {:reply, :ok, state}
- end
- def handle_cast({:test, name}, state) do
- process_list = Map.get(state, :process_list)
- {_, pid} = List.keyfind(process_list, name, 0)
- :erlang.process_info(pid, :messages) |> IO.inspect
- SecondProcess.test(pid)
- IO.puts("TEST FINISHED")
- {:noreply, state}
- end
- def handle_cast(_msg, state) do
- {:noreply, state}
- end
- def start_second_process(name) do
- GenServer.call(__MODULE__, {:start_second, name})
- end
- def test(user_name) do
- GenServer.cast(__MODULE__, {:test, user_name})
- IO.puts("TEST STARTED")
- end
Add Comment
Please, Sign In to add comment