16 lines
310 B
Elixir
16 lines
310 B
Elixir
|
defmodule TakeANumber do
|
||
|
def start() do
|
||
|
spawn(fn -> loop(0) end)
|
||
|
end
|
||
|
|
||
|
defp loop(number) do
|
||
|
new_state = receive do
|
||
|
:stop -> exit(:ok)
|
||
|
{:report_state, pid} -> send(pid, number)
|
||
|
{:take_a_number, pid} -> send(pid, number + 1)
|
||
|
_ -> number
|
||
|
end
|
||
|
loop(new_state)
|
||
|
end
|
||
|
end
|