Skip to content

Instantly share code, notes, and snippets.

@ne-sachirou
Created April 16, 2015 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ne-sachirou/acc578cf5dacd1b59d7e to your computer and use it in GitHub Desktop.
Save ne-sachirou/acc578cf5dacd1b59d7e to your computer and use it in GitHub Desktop.
Elixir short sample.
defmodule Count do
def f parent, cnt do
send parent, {:print, cnt}
receive do
:up -> Count.f parent, cnt + 1
_ ->
send parent, {:print, "バカ"}
Count.f parent, cnt
end
end
end
defmodule Main do
def start do
pid = spawn Count, :f, [self(), 0]
Main.loop pid
end
def loop pid do
send pid, :up
receive do
{:print, n} ->
IO.puts n
Main.loop pid
_ ->
IO.puts "アホ"
Main.loop pid
after 1000 ->
IO.puts "tick"
Main.loop pid
end
end
end
Main.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment