loop_handler_timeout_info_h.erl 591 B

1234567891011121314151617181920212223
  1. %% This module implements a loop handler that changes
  2. %% the timeout value to 500ms after the first message
  3. %% then sends itself another message after 1000ms.
  4. %% It is expected to timeout, that is, reply a 299.
  5. -module(loop_handler_timeout_info_h).
  6. -export([init/2]).
  7. -export([info/3]).
  8. -export([terminate/3]).
  9. init(Req, _) ->
  10. self() ! message,
  11. {cowboy_loop, Req, undefined}.
  12. info(message, Req, State) ->
  13. erlang:send_after(500, self(), message),
  14. {ok, Req, State, 100};
  15. info(timeout, Req, State) ->
  16. {stop, cowboy_req:reply(<<"299 OK!">>, Req), State}.
  17. terminate(stop, _, _) ->
  18. ok.