This commit is contained in:
Timofey Khoruzhii 2023-04-17 11:43:58 +03:00
commit 8293234a24
5 changed files with 107 additions and 0 deletions

View file

@ -0,0 +1,36 @@
defmodule Child do
def start_link do
GenServer.start_link(__MODULE__, [])
end
def init(_args) do
{:ok, 0}
end
def handle_info({:info, n}, state) do
IO.puts "info #{n}"
{:noreply, state + n}
end
def handle_cast({:cast, n}, state) do
IO.puts "cast #{n}"
{:noreply, state + n}
end
def handle_call({:call, n}, _from, state) do
IO.puts "call #{n}"
{:reply, state + n, state + n}
end
end
defmodule ProcessCommunication do
def run do
{:ok, child} = Child.start_link()
send(child, {:info, 7})
GenServer.cast(child, {:cast, 17})
result = GenServer.call(child, {:call, 31})
IO.puts "Rusult: #{result}"
end
end