Skip to content

Instantly share code, notes, and snippets.

@jartur
Created July 9, 2010 14:48
Show Gist options
  • Save jartur/469550 to your computer and use it in GitHub Desktop.
Save jartur/469550 to your computer and use it in GitHub Desktop.
-module(geometry).
-export([startN/1]).
ringAgent(Next) ->
receive
{next, N} when Next =:= undefined ->
ringAgent(N);
kill -> Next ! kill;
M ->
io:format("~p received ~p~n", [self(), M]),
Next ! M,
ringAgent(Next)
end.
startN(1, Pid) -> Pid ! {next, spawn(geometry, ringAgent, [Pid])}, Pid;
startN(N, Pid) ->
startN(N-1, spawn(geometry, ringAgent, [Pid])).
startN(N) ->
startN(N, undefined).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment