From df2d9a951db85cb0ed8c16d0b7e8d42fd6ea0a58 Mon Sep 17 00:00:00 2001 From: Keewon Seo Date: Mon, 22 Jul 2013 20:23:54 +0900 Subject: [PATCH 1/2] don't fail to init() and keep reconnecting if reconnect is true --- src/redo.erl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/redo.erl b/src/redo.erl index 51731ac..799c292 100644 --- a/src/redo.erl +++ b/src/redo.erl @@ -138,7 +138,15 @@ init([Opts]) -> State1 when is_record(State1, state) -> {ok, State1}; Err -> - {stop, Err} + case State#state.reconnect of + true -> + erlang:send_after(1000, self(), timeout), + ?WARN("redo init error: ~p", [Err]), + {ok, State#state{sock=undefined}}; + _ -> + {stop, Err} + end + end. %%-------------------------------------------------------------------- From e167db4d9cf142a36fd707ab13089267ee03430a Mon Sep 17 00:00:00 2001 From: Keewon Seo Date: Mon, 22 Jul 2013 22:17:07 +0900 Subject: [PATCH 2/2] use return value of init instead of send_after --- src/redo.erl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/redo.erl b/src/redo.erl index 799c292..f832a26 100644 --- a/src/redo.erl +++ b/src/redo.erl @@ -140,9 +140,8 @@ init([Opts]) -> Err -> case State#state.reconnect of true -> - erlang:send_after(1000, self(), timeout), ?WARN("redo init error: ~p", [Err]), - {ok, State#state{sock=undefined}}; + {ok, State#state{sock=undefined}, 1000}; _ -> {stop, Err} end