summaryrefslogtreecommitdiff
path: root/counter.erl
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-10-27 19:22:43 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-10-27 19:22:43 +0100
commita41822aa0165da09108674c9de894fff5d69b121 (patch)
tree0475b57e9b67018d45392cce8c726d172b8ec8c7 /counter.erl
parentd1a3332e4fb1ebfef754ab361834f040d075ca68 (diff)
Add set
Diffstat (limited to 'counter.erl')
-rw-r--r--counter.erl13
1 files changed, 9 insertions, 4 deletions
diff --git a/counter.erl b/counter.erl
index 9282b1b..915f5a9 100644
--- a/counter.erl
+++ b/counter.erl
@@ -1,6 +1,6 @@
-module(counter).
--export([start/0, count/1, next/0, stop/0]).
+-export([start/0, count/1, next/0, set/1, stop/0]).
start() ->
register(counterPid, spawn(?MODULE, count, [0])).
@@ -10,11 +10,16 @@ count(N) when N > 32767 ->
count(N) ->
receive
{next, FromPID} ->
- FromPID ! {next, N};
+ FromPID ! {next, N},
+ count(N+1);
+ {set, New} ->
+ count(New);
{stop} ->
exit(normal)
- end,
- count(N+1).
+ end.
+
+set(N) ->
+ counterPid ! {set, N}.
next() ->
counterPid ! {next, self()},