From a41822aa0165da09108674c9de894fff5d69b121 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 27 Oct 2015 19:22:43 +0100 Subject: Add set --- counter.erl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'counter.erl') 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()}, -- cgit v1.2.3