aboutsummaryrefslogblamecommitdiffstats
path: root/test/notify_and_wait_protocol.erl
blob: 26f69079b99f8e7fb373eb5cb0d3f0aeeb4c6cb9 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                                  
                           
 
                        
                  
 




                                                                               

                  


                                                           
-module(notify_and_wait_protocol).
-behaviour(ranch_protocol).

-export([start_link/3]).
-export([init/4]).

start_link(_, _, Opts = #{pid := TestPid}) ->
	Msg = maps:get(msg, Opts, connected),
	TerminateMsg = maps:get(terminate_msg, Opts, stop),
	Timeout = maps:get(timeout, Opts, infinity),
	Pid = spawn_link(?MODULE, init, [Msg, TestPid, TerminateMsg, Timeout]),
	{ok, Pid}.

init(Msg, Pid, TerminateMsg, Timeout) ->
	Pid ! {self(), Msg},
	receive TerminateMsg -> ok after Timeout -> ok end.