From eb74e3d30ca9fa47268d3a235f928341fb807423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 26 Apr 2019 14:57:34 +0200 Subject: Add the supervise option to start without supervisor --- src/gun.erl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/gun.erl') diff --git a/src/gun.erl b/src/gun.erl index d8aa15b..c2054e0 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -111,6 +111,7 @@ protocols => [http | http2], retry => non_neg_integer(), retry_timeout => pos_integer(), + supervise => boolean(), trace => boolean(), transport => tcp | tls | ssl, transport_opts => [gen_tcp:connect_option()] | [ssl:connect_option()], @@ -211,7 +212,11 @@ do_open(Host, Port, Opts0) -> end, case check_options(maps:to_list(Opts)) of ok -> - case supervisor:start_child(gun_sup, [self(), Host, Port, Opts]) of + Result = case maps:get(supervise, Opts, true) of + true -> supervisor:start_child(gun_sup, [self(), Host, Port, Opts]); + false -> start_link(self(), Host, Port, Opts) + end, + case Result of OK = {ok, ServerPid} -> consider_tracing(ServerPid, Opts), OK; @@ -260,6 +265,8 @@ check_options([{retry, R}|Opts]) when is_integer(R), R >= 0 -> check_options(Opts); check_options([{retry_timeout, T}|Opts]) when is_integer(T), T >= 0 -> check_options(Opts); +check_options([{supervise, B}|Opts]) when B =:= true; B =:= false -> + check_options(Opts); check_options([{trace, B}|Opts]) when B =:= true; B =:= false -> check_options(Opts); check_options([{transport, T}|Opts]) when T =:= tcp; T =:= tls -> -- cgit v1.2.3