test/handlers/delay_hello_h.erl
raw| 1 | %% This module sends a hello world response after a delay. |
| 2 | |
| 3 | -module(delay_hello_h). |
| 4 | |
| 5 | -export([init/2]). |
| 6 | |
| 7 | init(Req, Delay) when is_integer(Delay) -> |
| 8 | init(Req, #{delay => Delay}); |
| 9 | init(Req, Opts=#{delay := Delay}) -> |
| 10 | _ = case Opts of |
| 11 | #{notify_received := Pid} -> |
| 12 | Pid ! {request_received, maps:get(path, Req)}; |
| 13 | _ -> |
| 14 | ok |
| 15 | end, |
| 16 | timer:sleep(Delay), |
| 17 | {ok, cowboy_req:reply(200, #{}, <<"Hello world!">>, Req), Delay}. |