aboutsummaryrefslogtreecommitdiffstats
path: root/src/gun.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/gun.erl')
-rw-r--r--src/gun.erl30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/gun.erl b/src/gun.erl
index b3623eb..074b121 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -48,6 +48,9 @@
-export([await_body/2]).
-export([await_body/3]).
-export([await_body/4]).
+-export([await_up/1]).
+-export([await_up/2]).
+-export([await_up/3]).
%% Flushing gun messages.
-export([flush/1]).
@@ -333,6 +336,33 @@ await_body(ServerPid, StreamRef, Timeout, MRef, Acc) ->
{error, timeout}
end.
+-spec await_up(pid()) -> {ok, http | spdy} | {error, atom()}.
+await_up(ServerPid) ->
+ MRef = monitor(process, ServerPid),
+ Res = await_up(ServerPid, 5000, MRef),
+ demonitor(MRef, [flush]),
+ Res.
+
+-spec await_up(pid(), reference() | timeout()) -> {ok, http | spdy} | {error, atom()}.
+await_up(ServerPid, MRef) when is_reference(MRef) ->
+ await_up(ServerPid, 5000, MRef);
+await_up(ServerPid, Timeout) ->
+ MRef = monitor(process, ServerPid),
+ Res = await_up(ServerPid, Timeout, MRef),
+ demonitor(MRef, [flush]),
+ Res.
+
+-spec await_up(pid(), timeout(), reference()) -> {ok, http | spdy} | {error, atom()}.
+await_up(ServerPid, Timeout, MRef) ->
+ receive
+ {gun_up, ServerPid, Protocol} ->
+ {ok, Protocol};
+ {'DOWN', MRef, process, ServerPid, Reason} ->
+ {error, Reason}
+ after Timeout ->
+ {error, timeout}
+ end.
+
-spec flush(pid() | reference()) -> ok.
flush(ServerPid) when is_pid(ServerPid) ->
flush_pid(ServerPid);