Skip to content

Instantly share code, notes, and snippets.

@topher6345
Created February 28, 2017 17:18
Show Gist options
  • Save topher6345/4e25d9ac0ea0fead3fe90493fa84b369 to your computer and use it in GitHub Desktop.
Save topher6345/4e25d9ac0ea0fead3fe90493fa84b369 to your computer and use it in GitHub Desktop.
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