From 2a857b0b1c7e98bc2b291487d21c966158b4d704 Mon Sep 17 00:00:00 2001 From: Gaurav Agarwal Date: Wed, 20 Mar 2024 12:47:05 +0530 Subject: [PATCH] Echo process with IO.write compatibility. --- examples/07-processes/echo.exs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 examples/07-processes/echo.exs 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")