summaryrefslogtreecommitdiff
path: root/src/counter.erl
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-11-03 01:12:28 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-11-03 01:12:28 +0100
commit2828b4ef0f4bb74edd39188f81dd6d3ee2a67ec6 (patch)
treea7a78fc7e78c090a1bd5149e77503006480c796f /src/counter.erl
parent3136befad02dcda0e10790608ab19c557d3141b4 (diff)
Implement counter as gen_server
Diffstat (limited to 'src/counter.erl')
-rw-r--r--src/counter.erl10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/counter.erl b/src/counter.erl
index b46503e..4f4b3f1 100644
--- a/src/counter.erl
+++ b/src/counter.erl
@@ -16,8 +16,14 @@ start_link() ->
init(_Args) ->
{ok, 0}.
-handle_call(_Request, _From, State) ->
- {reply, ok, State}.
+handle_call(next, _From, N) when N >= ?MAXCOUNT ->
+ {reply, 0, 0};
+handle_call(next, _From, N) ->
+ {reply, N + 1, N + 1};
+handle_call(get, _From, N) ->
+ {reply, N, N};
+handle_call({set, N}, _From, _N) ->
+ {reply, N, N}.
handle_cast(_Msg, State) ->
{noreply, State}.