Created
February 13, 2013 01:17
-
-
Save iaintshine/1f4c698d291bfabbb053 to your computer and use it in GitHub Desktop.
Erlang echo example
This file contains hidden or 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(echo). | |
-compile(export_all). | |
go() -> | |
register(echo, spawn(echo, loop, [])), | |
echo ! { self(), hello }, | |
receive | |
{ _Pid, Msg } -> | |
io:format("~w~n", [Msg]) | |
end, | |
echo ! stop. | |
loop() -> | |
receive | |
{ From, Msg } -> | |
From ! { self(), Msg }, | |
loop(); | |
stop -> | |
true | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment