stamina-0.1.0.2: Retries for humans
Safe HaskellSafe-Inferred
LanguageGHC2021

Stamina

Synopsis

Documentation

retry :: (MonadCatch m, MonadIO m) => RetrySettings -> (RetryStatus -> m a) -> m a Source #

Retry on all sync exceptions, async exceptions will still be thrown.

The backoff delays between retries grow exponentially plus a random jitter. The backoff for retry attempt number _attempt_ is computed as:

   backoffExpBase ** (attempt - 1) + random(0, backoffJitter)

With the default values, the backoff for the first 5 attempts will be:

   2 ** 0 + random(0, 1) = 1 + random(0, 1)
   2 ** 1 + random(0, 1) = 2 + random(0, 1)
   2 ** 2 + random(0, 1) = 4 + random(0, 1)
   2 ** 3 + random(0, 1) = 8 + random(0, 1)
   2 ** 4 + random(0, 1) = 16 + random(0, 1)

If all retries fail, the last exception is let through.

retryFor :: (Exception exc, MonadIO m, MonadCatch m) => RetrySettings -> (exc -> m RetryAction) -> (RetryStatus -> m a) -> m a Source #

data RetrySettings Source #

Settings for the retry functions.

Constructors

RetrySettings 

Fields

data RetryAction Source #

Instances

Instances details
Show RetryAction Source # 
Instance details

Defined in Stamina

Eq RetryAction Source # 
Instance details

Defined in Stamina

data RetryStatus Source #

Tracks the status of a retry

All fields will be zero if no retries have been attempted yet.

Constructors

RetryStatus 

Fields

escalateWith :: Exception exc => (err -> exc) -> Either err a -> IO a Source #

Escalate an Either to an exception by converting the Left value to an exception.

escalate :: Exception exc => Either exc a -> IO a Source #

Escalate an Either to an exception.

withLeft :: a -> Maybe b -> Either a b Source #

Convert a Maybe to an Either.