First commit
This commit is contained in:
commit
1dba0af064
36 changed files with 1065 additions and 0 deletions
23
chapter5/process_bottleneck.ex
Normal file
23
chapter5/process_bottleneck.ex
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue