Created
October 8, 2009 17:27
-
-
Save saivenkat/205209 to your computer and use it in GitHub Desktop.
A simple ping pong based actor example in Erlang
This file contains 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
-module(pingpong). | |
-export([ping/0, pong/0]). | |
ping()-> | |
receive | |
{Pid, ping} -> | |
io:fwrite("Ping received Pong~n",[]), | |
timer:sleep(3000), | |
Pid ! {self(), pong}, | |
ping(); | |
stop -> | |
true | |
end. | |
pong() -> | |
receive | |
{Pid, pong} -> | |
io:fwrite("Pong received Ping~n",[]), | |
timer:sleep(3000), | |
Pid ! {self(), ping}, | |
pong(); | |
stop -> | |
true | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment