Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defmodule Example do
- use GenServer
- def start_link(_) do
- GenServer.start_link __MODULE__, :ok, []
- end
- def init(:ok) do
- {:ok, []}
- end
- def add(pid,{first_name,last_name}) do
- GenServer.cast(pid,{:add, first_name, last_name})
- IO.puts("after calling add")
- end
- def handle_cast({:add, first_name, last_name},state) do
- task = Task.async(fn ->
- :timer.sleep(5_000)
- Enum.join([first_name,last_name]," ")
- end)
- {:noreply, state}
- end
- def handle_info({_ref, first_and_last_name}=msg,state) do
- IO.inspect(msg, label: "handle_info")
- {:noreply, [first_and_last_name | state]}
- end
- def handle_info(_, state), do: {:noreply, state}
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement