2014-04-26 13:46:55 +02:00
|
|
|
%% This module implements a loop handler that sends
|
|
|
|
%% itself a timeout that will intentionally arrive
|
|
|
|
%% too late, as it configures itself to only wait
|
|
|
|
%% 200ms before closing the connection in init/3.
|
|
|
|
%% This results in a 204 reply being sent back by Cowboy.
|
|
|
|
|
|
|
|
-module(loop_handler_timeout_h).
|
|
|
|
|
2014-09-26 15:58:44 +03:00
|
|
|
-export([init/2]).
|
2014-04-26 13:46:55 +02:00
|
|
|
-export([info/3]).
|
|
|
|
-export([terminate/3]).
|
|
|
|
|
2014-09-26 15:58:44 +03:00
|
|
|
init(Req, _) ->
|
2014-04-26 13:46:55 +02:00
|
|
|
erlang:send_after(1000, self(), timeout),
|
2014-09-26 15:58:44 +03:00
|
|
|
{long_polling, Req, undefined, 200, hibernate}.
|
2014-04-26 13:46:55 +02:00
|
|
|
|
|
|
|
info(timeout, Req, State) ->
|
2014-09-23 16:43:29 +03:00
|
|
|
{ok, cowboy_req:reply(500, Req), State}.
|
2014-04-26 13:46:55 +02:00
|
|
|
|
|
|
|
terminate({normal, timeout}, _, _) ->
|
|
|
|
ok.
|