Created
February 28, 2017 17:18
-
-
Save topher6345/4e25d9ac0ea0fead3fe90493fa84b369 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Toss do | |
def loop(state, parent) do | |
receive do | |
:die -> | |
send(parent, :dead) # | |
_ -> | |
IO.puts "hello from loop - #{state}" | |
send(parent, state) # | |
loop(state+1, parent) | |
end | |
end | |
def init do | |
initial_state = 0 | |
pid = self() | |
spawn_link( | |
fn -> loop(initial_state, pid) end | |
) | |
end | |
end | |
# usage - open iex | |
# Toss.init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment