Created
August 7, 2013 16:36
-
-
Save svdmitrij/90bf04aeec2c005575ed to your computer and use it in GitHub Desktop.
Counter process
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('counter'). | |
-export([incr/2, get_count/1, loop/1]). | |
loop(Count) -> | |
receive | |
{ incr, Add } -> | |
loop(Count + Add); | |
{ report, To } -> | |
To ! { count, Count }, | |
loop(Count) | |
end. | |
incr(Counter, Add) -> | |
Counter ! { incr, Add }. | |
get_count(Counter) -> | |
Counter ! { report, self() }, | |
receive | |
{ count, Count } -> Count | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment