Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. defmodule Pingpong.PongProcess do
  2. use GenServer
  3.  
  4. def start_link(state \\ nil), do: GenServer.start_link(__MODULE__, state, name: __MODULE__)
  5.  
  6. def init(state) do
  7. {:ok, state}
  8. end
  9.  
  10. def handle_info(:ping, state) do
  11. pong_process_pid = self()
  12. ping_process_pid = Process.whereis(Pingpong.PingProcess)
  13.  
  14. IO.puts("PONG from #{inspect(pong_process_pid)} to #{inspect(ping_process_pid)}")
  15. Process.sleep(1000)
  16. send(ping_process_pid, :pong)
  17.  
  18. {:noreply, state}
  19. end
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement