0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 20:30:23 +00:00

Add timeout to cowboy_loop

LH: I have added a test that does both hibernate and timeout
    and fixed a related issue. I also tweaked the docs and tests.
This commit is contained in:
jdamanalo 2023-03-09 15:54:41 +08:00 committed by Loïc Hoguin
parent a72bf4105f
commit a81dc8af9d
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
8 changed files with 165 additions and 25 deletions

View file

@ -0,0 +1,23 @@
%% This module implements a loop handler that changes
%% the timeout value to 500ms after the first message
%% then sends itself another message after 1000ms.
%% It is expected to timeout, that is, reply a 299.
-module(loop_handler_timeout_info_h).
-export([init/2]).
-export([info/3]).
-export([terminate/3]).
init(Req, _) ->
self() ! message,
{cowboy_loop, Req, undefined}.
info(message, Req, State) ->
erlang:send_after(200, self(), message),
{ok, Req, State, 100};
info(timeout, Req, State) ->
{stop, cowboy_req:reply(<<"299 OK!">>, Req), State}.
terminate(stop, _, _) ->
ok.