aboutsummaryrefslogtreecommitdiffstats
path: root/test/notify_and_wait_protocol.erl
blob: 26f69079b99f8e7fb373eb5cb0d3f0aeeb4c6cb9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-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.