Permalink
Browse files

Cancel the refresh timer in terminate/2.

  • Loading branch information...
1 parent 14b8397 commit 22ac46d2138a5cedf8cb6a7591a47bad1402f261 @jdavisp3 jdavisp3 committed Jun 8, 2013
Showing with 7 additions and 6 deletions.
  1. +7 −6 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.

1 comment on commit 22ac46d

@caub
caub commented on 22ac46d Jun 19, 2013

yes good catch

Please sign in to comment.