summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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()},