long_polling_sys_h.erl 567 B

1234567891011121314151617181920212223
  1. %% This module implements a loop handler that does nothing
  2. %% and expects a crash to happen.
  3. -module(long_polling_sys_h).
  4. -export([init/2]).
  5. -export([info/3]).
  6. -export([terminate/3]).
  7. init(Req, _) ->
  8. process_flag(trap_exit, true),
  9. erlang:send_after(500, self(), timeout),
  10. {cowboy_loop, Req, undefined}.
  11. info(timeout, Req, State) ->
  12. %% Send an unused status code to make sure there's no
  13. %% conflict with whatever Cowboy may send itself.
  14. {ok, cowboy_req:reply(<<"299 OK!">>, Req), State};
  15. info(_, Req, State) ->
  16. {ok, Req, State}.
  17. terminate(_, _, _) ->
  18. ok.