Skip to content

Commit 0d038d4

Browse files
authored
Merge pull request #24 from mbg/recoveringWithStatus
Add `recoveringWithStatus`
2 parents ae95dcb + 310321a commit 0d038d4

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/Network/Wait.hs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ module Network.Wait (
2727
waitSocketWith,
2828

2929
-- * Utility
30-
recoveringWith
30+
recoveringWith,
31+
recoveringWithStatus
3132
) where
3233

3334
-------------------------------------------------------------------------------
@@ -164,7 +165,7 @@ waitSocketWith
164165
=> [RetryStatus -> Handler m Bool] -> RetryPolicyM m -> AddrInfo
165166
-> m Socket
166167
waitSocketWith hs policy addr =
167-
recoveringWith hs policy $ \retryStatus ->
168+
recoveringWithStatus hs policy $ \retryStatus ->
168169
-- all of the networking code runs in IO
169170
liftIO $
170171
-- we want to make sure that we close the socket after every attempt;
@@ -194,8 +195,28 @@ waitSocketWith hs policy addr =
194195
-- the standard output or a logger.
195196
recoveringWith
196197
:: (MonadIO m, MonadMask m)
197-
=> [RetryStatus -> Handler m Bool] -> RetryPolicyM m -> (RetryStatus -> m a) -> m a
198-
recoveringWith hs policy action =
198+
=> [RetryStatus -> Handler m Bool] -> RetryPolicyM m -> m a -> m a
199+
recoveringWith hs policy =
200+
recoveringWithStatus hs policy . const
201+
202+
203+
-- | `recoveringWithStatus` @extraHandlers retryPolicy action@ will attempt to
204+
-- run @action@. If the @action@ fails, @retryPolicy@ is used
205+
-- to determine whether (and how often) this function should attempt to
206+
-- retry @action@. The `RetryStatus` is given to @action@ as argument.
207+
-- By default, this function will retry after all
208+
-- exceptions (except for those given by `skipAsyncExceptions`). This
209+
-- behaviour may be customised with @extraHandlers@ which are installed
210+
-- after `skipAsyncExceptions`, but before the default exception handler.
211+
-- The @extraHandlers@ may also be used to report retry attempts to e.g.
212+
-- the standard output or a logger.
213+
recoveringWithStatus
214+
:: (MonadIO m, MonadMask m)
215+
=> [RetryStatus -> Handler m Bool]
216+
-> RetryPolicyM m
217+
-> (RetryStatus -> m a)
218+
-> m a
219+
recoveringWithStatus hs policy action =
199220
-- apply the retry policy to the following code, with the combinations of
200221
-- the `skipAsyncExceptions`, given, and default handlers. The order of
201222
-- the handlers matters as they are checked in order.

src/Network/Wait/PostgreSQL.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ waitPostgreSqlWith
9393
=> [RetryStatus -> Handler m Bool] -> RetryPolicyM m -> info
9494
-> m Connection
9595
waitPostgreSqlWith hs policy info =
96-
recoveringWith hs policy $ \_ ->
96+
recoveringWith hs policy $
9797
liftIO $
9898
bracket (connectDb info) close $ \con -> do
9999
rs <- query_ @[Int] con "SELECT 1;"

src/Network/Wait/Redis.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ waitRedisWith
7979
:: (MonadIO m, MonadMask m)
8080
=> [RetryStatus -> Handler m Bool] -> RetryPolicyM m -> ConnectInfo
8181
-> m Connection
82-
waitRedisWith hs policy = recoveringWith hs policy . const . liftIO . checkedConnect
82+
waitRedisWith hs policy = recoveringWith hs policy . liftIO . checkedConnect
8383

8484
-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)