exercism/elixir/take-a-number/lib/take_a_number.ex

16 lines
310 B
Elixir
Raw Normal View History

2023-12-19 02:00:48 +00:00
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