retry 0.8.0.1 → 0.8.0.2
raw patch · 4 files changed
+21/−20 lines, 4 files
Files
- changelog.md +3/−0
- retry.cabal +1/−1
- src/Control/Retry.hs +7/−7
- test/Tests/Control/Retry.hs +10/−12
changelog.md view
@@ -1,3 +1,6 @@+0.8.0.2+* Update docs for default retry policy. [PR 64](https://github.com/Soostone/retry/pull/64)+ 0.8.0.1 * Loosen upper bounds
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.8.0.1+version: 0.8.0.2 synopsis: Retry combinators for monadic actions that may fail license: BSD3 license-file: LICENSE
src/Control/Retry.hs view
@@ -131,9 +131,9 @@ -- Naturally, 'mempty' will retry immediately (delay 0) for an -- unlimited number of retries, forming the identity for the 'Monoid'. ----- The default under 'def' implements a constant 50ms delay, up to 5 times:+-- The default retry policy 'retryPolicyDefault' implements a constant 50ms delay, up to 5 times: ----- >> def = constantDelay 50000 <> limitRetries 5+-- >> retryPolicyDefault = constantDelay 50000 <> limitRetries 5 -- -- For anything more complex, just define your own 'RetryPolicyM': --@@ -403,7 +403,7 @@ -- -- >>> import Data.Maybe -- >>> let f _ = putStrLn "Running action" >> return Nothing--- >>> retrying def (const $ return . isNothing) f+-- >>> retrying retryPolicyDefault (const $ return . isNothing) f -- Running action -- Running action -- Running action@@ -450,7 +450,7 @@ -- before finally failing for good: -- -- >>> let f _ = putStrLn "Running action" >> error "this is an error"--- >>> recoverAll def f+-- >>> recoverAll retryPolicyDefault f -- Running action -- Running action -- Running action@@ -509,7 +509,7 @@ :: (MonadIO m, MonadCatch m) #endif => RetryPolicyM m- -- ^ Just use 'def' for default settings+ -- ^ Just use 'retryPolicyDefault' for default settings -> [(RetryStatus -> Handler m Bool)] -- ^ Should a given exception be retried? Action will be -- retried if this returns True *and* the policy allows it.@@ -555,7 +555,7 @@ :: (MonadIO m, MonadCatch m) #endif => RetryPolicyM m- -- ^ Just use 'def' for default settings+ -- ^ Just use 'retryPolicyDefault' for default settings -> [(RetryStatus -> Handler m Bool)] -- ^ Should a given exception be retried? Action will be -- retried if this returns True *and* the policy allows it.@@ -725,7 +725,7 @@ -- instance Exception AnotherException --- test = retrying def [h1,h2] f+-- test = retrying retryPolicyDefault [h1,h2] f -- where -- f = putStrLn "Running action" >> throwM AnotherException -- h1 = Handler $ \ (e :: TestException) -> return False
test/Tests/Control/Retry.hs view
@@ -8,9 +8,7 @@ import Control.Applicative import Control.Concurrent import Control.Concurrent.STM as STM-import Control.Exception (AsyncException (..), IOException,- MaskingState (..),- getMaskingState, throwTo)+import qualified Control.Exception as EX import Control.Monad.Catch import Control.Monad.Identity import Control.Monad.IO.Class@@ -72,7 +70,7 @@ recoverAll (limitRetries 2) (const work) `finally` putMVar done () atomically (STM.check . (== 1) =<< readTVar counter)- throwTo tid UserInterrupt+ EX.throwTo tid EX.UserInterrupt takeMVar done @@ -225,26 +223,26 @@ maskingStateTests :: TestTree maskingStateTests = testGroup "masking state" [ testCase "shouldn't change masking state in a recovered action" $ do- maskingState <- getMaskingState+ maskingState <- EX.getMaskingState final <- try $ recovering retryPolicyDefault testHandlers $ const $ do- maskingState' <- getMaskingState+ maskingState' <- EX.getMaskingState maskingState' @?= maskingState fail "Retrying..." assertBool- ("Expected IOException but didn't get one")- (isLeft (final :: Either IOException ()))+ ("Expected EX.IOException but didn't get one")+ (isLeft (final :: Either EX.IOException ())) , testCase "should mask asynchronous exceptions in exception handlers" $ do let checkMaskingStateHandlers = [ const $ Handler $ \(_ :: SomeException) -> do- maskingState <- getMaskingState- maskingState @?= MaskedInterruptible+ maskingState <- EX.getMaskingState+ maskingState @?= EX.MaskedInterruptible return shouldRetry ] final <- try $ recovering retryPolicyDefault checkMaskingStateHandlers $ const $ fail "Retrying..." assertBool- ("Expected IOException but didn't get one")- (isLeft (final :: Either IOException ()))+ ("Expected EX.IOException but didn't get one")+ (isLeft (final :: Either EX.IOException ())) ]