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やってみた。
Scheduler調べてみた。

サンプルコード

defmodule FibSolver do
	def fib(scheduler) do
		send scheduler, {:ready, self()}
		receive do
			{:fib, n, client} ->
			    IO.puts "ok1"
				send client, {:answer, n, fib_calc(n), self()}
				fib(scheduler)
			{:shutdown} ->
			    IO.puts "ok3"
				exit(0)
		end
	end
	defp fib_calc(0), do: 1
	defp fib_calc(1), do: 1
	defp fib_calc(n), do: fib_calc(n - 1) + fib_calc(n - 2)
end

Enum.each 1..3, fn n ->
    IO.puts n
end
(1..3)
|> Enum.map(fn(n) ->
    IO.puts n
end)
spawn(FibSolver, :fib, [self()])
receive do
	{:ready, pid} ->
        IO.puts "ok0"
        send pid, {:fib, 9, self()}
	#{:answer, number, result, _pid} ->
    #    IO.puts "ok1"
end
receive do
	#{:ready, pid} ->
    #    IO.puts "ok0"
    #    send pid, {:fib, 9, self()}
	{:answer, number, result, _pid} ->
        IO.puts "ok2"
        IO.puts result
        send _pid, {:shutdown}
end


実行結果

1
2
3
1
2
3
ok0
ok1
ok2
55
ok3

成果物

以上。

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?