diff --git a/examples/07-processes/echo.exs b/examples/07-processes/echo.exs new file mode 100644 index 0000000..bdfda57 --- /dev/null +++ b/examples/07-processes/echo.exs @@ -0,0 +1,22 @@ +defmodule Echo do + def start do + {:ok, echo_pid} = Task.start fn -> loop() end + Process.register(echo_pid, :echo) + echo_pid + end + + def loop do + receive do + {:io_request, caller, reply_as, msg} -> + IO.inspect msg + send(caller, {:io_reply, reply_as, msg}) + loop() + msg -> + IO.inspect msg + loop() + end + end +end + +Echo.start +# IO.write(:echo, "hello")