ws_timeout_cancel.erl 543 B

1234567891011121314151617181920
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. -module(ws_timeout_cancel).
  3. -export([init/2]).
  4. -export([websocket_handle/2]).
  5. -export([websocket_info/2]).
  6. init(Req, _) ->
  7. erlang:start_timer(500, self(), should_not_cancel_timer),
  8. {cowboy_websocket, Req, undefined, 1000}.
  9. websocket_handle({text, Data}, State) ->
  10. {reply, {text, Data}, State};
  11. websocket_handle({binary, Data}, State) ->
  12. {reply, {binary, Data}, State}.
  13. websocket_info(_Info, State) ->
  14. erlang:start_timer(500, self(), should_not_cancel_timer),
  15. {ok, State}.