| 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 |
|
| 6 |
-module(loop_handler_timeout_info_h). |
| 7 |
|
| 8 |
-export([init/2]). |
| 9 |
-export([info/3]). |
| 10 |
-export([terminate/3]). |
| 11 |
|
| 12 |
init(Req, _) -> |
| 13 |
self() ! message, |
| 14 |
{cowboy_loop, Req, undefined}. |
| 15 |
|
| 16 |
info(message, Req, State) -> |
| 17 |
erlang:send_after(500, self(), message), |
| 18 |
{ok, Req, State, 100}; |
| 19 |
info(timeout, Req, State) -> |
| 20 |
{stop, cowboy_req:reply(<<"299 OK!">>, Req), State}. |
| 21 |
|
| 22 |
terminate(stop, _, _) -> |
| 23 |
ok. |