1
%% Feel free to use, reuse and abuse the code in this file.
3
-module(http_handler_long_polling).
4
-behaviour(cowboy_http_handler).
5
-export([init/3, handle/2, info/3, terminate/2]).
7
init({_Transport, http}, Req, _Opts) ->
8
erlang:send_after(500, self(), timeout),
9
{loop, Req, 9, 5000, hibernate}.
11
handle(_Req, _State) ->
14
info(timeout, Req, 0) ->
15
{ok, Req2} = cowboy_http_req:reply(102, Req),
17
info(timeout, Req, State) ->
18
erlang:send_after(500, self(), timeout),
19
{loop, Req, State - 1, hibernate}.
21
terminate(_Req, _State) ->