packages feed

retry 0.8.1.2 → 0.9.0.0

raw patch · 4 files changed

+20/−13 lines, 4 files

Files

changelog.md view
@@ -1,3 +1,7 @@+0.9.0.0+* Replace several uses of RetryPolicy type alias with RetryPolicyM m for better+  GHC 9 compat.+ 0.8.1.2 * Set lower bound on base to >= 4.8 
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.1.2+version:             0.9.0.0 synopsis:            Retry combinators for monadic actions that may fail license:             BSD3 license-file:        LICENSE
src/Control/Retry.hs view
@@ -130,7 +130,7 @@ -- One can easily define an exponential backoff policy with a limited -- number of retries: ----- >> limitedBackoff = exponentialBackoff 50 <> limitRetries 5+-- >> limitedBackoff = exponentialBackoff 50000 <> limitRetries 5 -- -- Naturally, 'mempty' will retry immediately (delay 0) for an -- unlimited number of retries, forming the identity for the 'Monoid'.@@ -141,7 +141,7 @@ -- -- For anything more complex, just define your own 'RetryPolicyM': ----- >> myPolicy = retryPolicy $ \ rs -> if rsIterNumber n > 10 then Just 1000 else Just 10000+-- >> myPolicy = retryPolicy $ \ rs -> if rsIterNumber rs > 10 then Just 1000 else Just 10000 -- -- Since 0.7. newtype RetryPolicyM m = RetryPolicyM { getRetryPolicyM :: RetryStatus -> m (Maybe Int) }@@ -153,7 +153,7 @@ type RetryPolicy = forall m . Monad m => RetryPolicyM m  -- | Default retry policy-retryPolicyDefault :: RetryPolicy+retryPolicyDefault :: (Monad m) => RetryPolicyM m retryPolicyDefault = constantDelay 50000 <> limitRetries 5  @@ -303,7 +303,7 @@ ------------------------------------------------------------------------------- -- | Helper for making simplified policies that don't use the monadic -- context.-retryPolicy :: (RetryStatus -> Maybe Int) -> RetryPolicy+retryPolicy :: (Monad m) => (RetryStatus -> Maybe Int) -> RetryPolicyM m retryPolicy f = RetryPolicyM $ \ s -> return (f s)  @@ -355,9 +355,10 @@ ------------------------------------------------------------------------------- -- | Implement a constant delay with unlimited retries. constantDelay-    :: Int+    :: (Monad m)+    => Int     -- ^ Base delay in microseconds-    -> RetryPolicy+    -> RetryPolicyM m constantDelay delay = retryPolicy (const (Just delay))  @@ -365,9 +366,10 @@ -- | Grow delay exponentially each iteration.  Each delay will -- increase by a factor of two. exponentialBackoff-    :: Int+    :: (Monad m)+    => Int     -- ^ Base delay in microseconds-    -> RetryPolicy+    -> RetryPolicyM m exponentialBackoff base = retryPolicy $ \ RetryStatus { rsIterNumber = n } ->   Just $! base `boundedMult` boundedPow 2 n @@ -381,7 +383,7 @@ -- -- sleep = temp \/ 2 + random_between(0, temp \/ 2) fullJitterBackoff-    :: MonadIO m+    :: (MonadIO m)     => Int     -- ^ Base delay in microseconds     -> RetryPolicyM m@@ -394,9 +396,10 @@ ------------------------------------------------------------------------------- -- | Implement Fibonacci backoff. fibonacciBackoff-    :: Int+    :: (Monad m)+    => Int     -- ^ Base delay in microseconds-    -> RetryPolicy+    -> RetryPolicyM m fibonacciBackoff base = retryPolicy $ \RetryStatus { rsIterNumber = n } ->   Just $ fib (n + 1) (0, base)     where
test/Tests/Control/Retry.hs view
@@ -400,7 +400,7 @@ ------------------------------------------------------------------------------- -- | Generate an arbitrary 'RetryPolicy' without any limits applied. genPolicyNoLimit-    :: (MonadGen mg, MonadIO mr)+    :: forall mg mr. (MonadGen mg, MonadIO mr)     => Range Int     -> mg (RetryPolicyM mr) genPolicyNoLimit durationRange =