Skip to content

Instantly share code, notes, and snippets.

@joshchernoff joshchernoff/A.ex
Last active Feb 4, 2017

Embed
What would you like to do?
defmodule A
def init do
collector = spawn(B, :loop, [[], self])
states = [%{"or" => "oregon"}, %{"wa" => "washington"}]
states |> Enum.each(fn (state) ->
send(collector, {:ok, state})
end)
send(collector, :exit)
end
def loop() do
receive do
{:exit, result} ->
IO.inspect results
_ ->
loop()
end
end
defmodule B
def loop(results \\ [], parent) do
receive do
{:ok, result} ->
new_results = [result|results]
loop(new_results, parent)
:exit ->
send(parent, {:exit, results})
_ ->
loop(results, parent)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.