elixir-in-action/chapter5/process_bottleneck.ex

24 lines
369 B
Elixir
Raw Normal View History

2020-06-20 13:57:33 -05:00
defmodule Server do
def start do
spawn(fn -> loop() end)
end
def send_msg(server, message) do
send(server, {self(), message})
receive do
{:response, response} -> response
end
end
def loop do
receive do
{caller, message} ->
Process.sleep(1000)
send(caller, {:response, message})
end
loop()
end
end