Skip to content

Commit 37883dc

Browse files
committed
defer starting gun to handle_continue so init is fast
1 parent b0fe7f2 commit 37883dc

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/nouveau/src/nouveau_gun.erl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
-export([handle_call/3]).
3030
-export([handle_cast/2]).
3131
-export([handle_info/2]).
32+
-export([handle_continue/2]).
3233

3334
% config_listener callbacks
3435
-export([handle_config_change/5]).
@@ -44,27 +45,26 @@ host_header() ->
4445

4546
init(_) ->
4647
URL = nouveau_util:nouveau_url(),
47-
case start_gun(URL) of
48-
{ok, _PoolPid} ->
49-
ok = config:listen_for_changes(?MODULE, URL),
50-
{ok, nil};
51-
{error, Reason} ->
52-
{error, Reason}
53-
end.
48+
ok = config:listen_for_changes(?MODULE, URL),
49+
{ok, URL, {continue, start_gun}}.
5450

5551
handle_call(_Msg, _From, State) ->
5652
{reply, unexpected_msg, State}.
5753

5854
handle_cast(_Msg, State) ->
5955
{noreply, State}.
6056

61-
handle_info(restart_config_listener, State) ->
62-
ok = config:listen_for_changes(?MODULE, nil),
63-
{noreply, State};
64-
handle_info(Msg, State) ->
65-
couch_log:warning("~p received unexpected message: ~p", [?MODULE, Msg]),
57+
handle_info(_Msg, State) ->
6658
{noreply, State}.
6759

60+
handle_continue(start_gun, URL) ->
61+
case start_gun(URL) of
62+
{ok, _ManagerPid} ->
63+
{noreply, URL};
64+
{error, Reason} ->
65+
{stop, Reason}
66+
end.
67+
6868
handle_config_change("nouveau", "url", URL, _Persist, OldURL) ->
6969
case start_gun(URL) of
7070
{ok, _PoolPid} ->

0 commit comments

Comments
 (0)