retry 0.3.0.0 → 0.4
raw patch · 2 files changed
+33/−20 lines, 2 filesdep +exceptionsdep −lifted-basedep −monad-control
Dependencies added: exceptions
Dependencies removed: lifted-base, monad-control
Files
- retry.cabal +4/−4
- src/Control/Retry.hs +29/−16
retry.cabal view
@@ -14,7 +14,7 @@ case we should hang back for a bit and retry the query instead of simply raising an exception. -version: 0.3.0.0+version: 0.4 synopsis: Retry combinators for monadic actions that may fail license: BSD3 license-file: LICENSE@@ -24,13 +24,13 @@ category: Control build-type: Simple cabal-version: >=1.10+Homepage: http://github.com/Soostone/retry library exposed-modules: Control.Retry build-depends: - base ==4.*, - monad-control,- lifted-base,+ base ==4.*, + exceptions >= 0.5 && < 0.6, transformers, data-default hs-source-dirs: src
src/Control/Retry.hs view
@@ -1,9 +1,11 @@-{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE ScopedTypeVariables #-}+ ----------------------------------------------------------------------------- -- | -- Module : Control.Retry@@ -29,7 +31,7 @@ ( -- * High Level Operation RetrySettings (..)- , RetryLimit+ , RetryLimit(..) , limitedRetries , unlimitedRetries @@ -42,15 +44,15 @@ , performDelay , flatDelay , backoffDelay+ , backoffDelayFor ) where ------------------------------------------------------------------------------- import Control.Concurrent-import Control.Exception.Lifted+import Control.Monad.Catch import Control.Monad.IO.Class-import Control.Monad.Trans.Control import Data.Default-import Prelude hiding (catch)+import Prelude hiding (catch) ------------------------------------------------------------------------------- @@ -90,9 +92,20 @@ -- | Delay thread using backoff delay for the nth retry.-backoffDelay :: (Integral b, MonadIO m) => RetrySettings -> b -> m ()-backoffDelay set@RetrySettings{..} !n = liftIO (threadDelay (2^n * delay set))+backoffDelay :: MonadIO m => RetrySettings -> Int -> m ()+backoffDelay set !n = liftIO . threadDelay $ backoffDelayFor (delay set) n ++-- | Delay for nth iteration of exponential backoff, in microseconds+backoffDelayFor+ :: Int+ -- ^ Base delay in microseconds+ -> Int+ -- ^ Iteration number, starting at 0.+ -> Int+backoffDelayFor base n = 2^n * base++ -- | Delay thread using flat delay flatDelay :: MonadIO m => RetrySettings -> t -> m () flatDelay set@RetrySettings{..} !_ = liftIO (threadDelay $ delay set)@@ -162,7 +175,7 @@ -- Running action -- Running action -- *** Exception: this is an error-recoverAll :: (MonadIO m, MonadBaseControl IO m)+recoverAll :: (MonadIO m, MonadCatch m) => RetrySettings -> m a -> m a@@ -181,7 +194,7 @@ -- | Run an action and recover from a raised exception by potentially -- retrying the action a number of times.-recovering :: forall m a. (MonadIO m, MonadBaseControl IO m)+recovering :: forall m a. (MonadIO m, MonadCatch m) => RetrySettings -- ^ Just use 'def' faor default settings -> [Handler m Bool]@@ -206,8 +219,8 @@ True -> case numRetries of RNoLimit -> retry n- RLimit lim -> if n >= lim then throw e else retry n- False -> throw e+ RLimit lim -> if n >= lim then throwM e else retry n+ False -> throwM e go n = f `catches` map (transHandler n) hs