Skip to content

Instantly share code, notes, and snippets.

@aardvarrk
Created December 1, 2012 19:38
Show Gist options
  • Select an option

  • Save aardvarrk/4184427 to your computer and use it in GitHub Desktop.

Select an option

Save aardvarrk/4184427 to your computer and use it in GitHub Desktop.
foo() ->
Object = spawn(?MODULE, bar, [42]),
Object ! {add, 42},
Object ! {get, self()},
receive
Num -> io:printf("~s~n", [Num]) % prints 84
end.
bar(Num) ->
receive
{add, X} -> bar(Num + X);
{sub, X} -> bar(Num - X);
{mul, X} -> bar(Num * X);
{get, Pid} -> Pid ! Num, bar(Num)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment