-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
118 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
%% This module implements a loop handler that reads | ||
%% the request query for a timeout value, then sends | ||
%% itself a message after 1000ms. It replies a 200 when | ||
%% the message does not timeout and a 299 otherwise. | ||
|
||
-module(loop_idle_timeout_h). | ||
|
||
-export([init/2]). | ||
-export([info/3]). | ||
-export([terminate/3]). | ||
|
||
init(Req, _) -> | ||
#{timeout := Timeout} = cowboy_req:match_qs([{timeout, int}], Req), | ||
erlang:send_after(1000, self(), message), | ||
{cowboy_loop, Req, 2, Timeout}. | ||
|
||
info(message, Req, State) -> | ||
{stop, cowboy_req:reply(200, Req), State}; | ||
info(timeout, Req, State) -> | ||
{stop, cowboy_req:reply(<<"299 OK!">>, Req), State}. | ||
|
||
terminate(stop, _, _) -> | ||
ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_new_timeout_h). | ||
|
||
-export([init/2]). | ||
-export([info/3]). | ||
-export([terminate/3]). | ||
|
||
init(Req, _) -> | ||
self() ! message, | ||
{cowboy_loop, Req, 2}. | ||
|
||
info(message, Req, State) -> | ||
erlang:send_after(1000, self(), message), | ||
{ok, Req, State, 500}; | ||
info(timeout, Req, State) -> | ||
{stop, cowboy_req:reply(<<"299 OK!">>, Req), State}. | ||
|
||
terminate(stop, _, _) -> | ||
ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters