概要
paiza.ioでelixirやってみた。
Process調べてみた。
サンプルコード
pid = spawn fn ->
IO.puts 5 * 7
end
self
|> IO.inspect
Process.alive? pid
|> IO.inspect
Process.alive? self
|> IO.inspect
Process.info self
|> IO.inspect
defmodule ProcessTest do
def do_receive do
receive do
{:key, msg} ->
"match " <> msg
{:other, msg} ->
"not match" <> msg
after
1_000 ->
"after 1sec"
end
end
end
send self, {:key, "value"}
|> IO.inspect
send self, {:other, "other"}
|> IO.inspect
:erlang.process_info(self(), :message_queue_len)
|> IO.inspect
IO.puts ProcessTest.do_receive
:erlang.process_info(self(), :message_queue_len)
|> IO.inspect
IO.puts ProcessTest.do_receive
:erlang.process_info(self(), :message_queue_len)
|> IO.inspect
IO.puts ProcessTest.do_receive
実行結果
35
#PID<0.92.0>
#PID<0.95.0>
#PID<0.92.0>
#PID<0.92.0>
{:key, "value"}
{:other, "other"}
{:message_queue_len, 2}
match value
{:message_queue_len, 1}
not matchother
{:message_queue_len, 0}
after 1sec
成果物
以上。