Skip to content

Instantly share code, notes, and snippets.

@svdmitrij
Created August 7, 2013 16:36
Show Gist options
  • Save svdmitrij/90bf04aeec2c005575ed to your computer and use it in GitHub Desktop.
Save svdmitrij/90bf04aeec2c005575ed to your computer and use it in GitHub Desktop.
Counter process
-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