ws_timeout_cancel.erl 567 B

12345678910111213141516171819202122
  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, #{
  9. idle_timeout => 1000
  10. }}.
  11. websocket_handle({text, Data}, State) ->
  12. {reply, {text, Data}, State};
  13. websocket_handle({binary, Data}, State) ->
  14. {reply, {binary, Data}, State}.
  15. websocket_info(_Info, State) ->
  16. erlang:start_timer(500, self(), should_not_cancel_timer),
  17. {ok, State}.