1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

概要

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

成果物

以上。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?