summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/clock/src/stream_handler.erl13
1 files changed, 7 insertions, 6 deletions
diff --git a/examples/clock/src/stream_handler.erl b/examples/clock/src/stream_handler.erl
index 4f18b9d..2f08342 100644
--- a/examples/clock/src/stream_handler.erl
+++ b/examples/clock/src/stream_handler.erl
@@ -12,8 +12,8 @@
init(_Transport, Req, _Opts, _Active) ->
io:format("bullet init~n"),
- _ = erlang:send_after(?PERIOD, self(), refresh),
- {ok, Req, undefined}.
+ TRef = erlang:send_after(?PERIOD, self(), refresh),
+ {ok, Req, TRef}.
stream(<<"ping">>, Req, State) ->
io:format("ping received~n"),
@@ -22,15 +22,16 @@ stream(Data, Req, State) ->
io:format("stream received ~s~n", [Data]),
{ok, Req, State}.
-info(refresh, Req, State) ->
- _ = erlang:send_after(?PERIOD, self(), refresh),
+info(refresh, Req, _) ->
+ TRef = erlang:send_after(?PERIOD, self(), refresh),
DateTime = cowboy_clock:rfc1123(),
io:format("clock refresh timeout: ~s~n", [DateTime]),
- {reply, DateTime, Req, State};
+ {reply, DateTime, Req, TRef};
info(Info, Req, State) ->
io:format("info received ~p~n", [Info]),
{ok, Req, State}.
-terminate(_Req, _State) ->
+terminate(_Req, TRef) ->
io:format("bullet terminate~n"),
+ erlang:cancel_timer(TRef),
ok.