Module

Control.Monad.Aff.Retry

Package
purescript-aff-retry
Repository
Unisay/purescript-aff-retry

#RetryStatus Source

newtype RetryStatus

Datatype with stats about retries made thus far

Constructors

Instances

#RetryPolicyM Source

newtype RetryPolicyM m

A 'RetryPolicyM' is a function that takes an 'RetryStatus' and possibly returns a delay in milliseconds. Iteration numbers start at zero and increase by one on each retry. A Nothing return value from the function implies we have reached the retry limit.

Please note that 'RetryPolicyM' is a 'Monoid'. You can collapse multiple strategies into one using 'mappend' or '<>'. The semantics of this combination are as follows:

  1. If either policy returns 'Nothing', the combined policy returns 'Nothing'. This can be used to @inhibit@ after a number of retries, for example.

  2. If both policies return a delay, the larger delay will be used. This is quite natural when combining multiple policies to achieve a certain effect.

Example:

One can easily define an exponential backoff policy with a limited number of retries:

Naturally, 'mempty' will retry immediately (delay 0) for an unlimited number of retries, forming the identity for the 'Monoid'.

Constructors

Instances

#RetryPolicy Source

type RetryPolicy = forall m f. MonadAff f m => RetryPolicyM m

#retryPolicy Source

retryPolicy :: (RetryStatus -> Maybe Milliseconds) -> RetryPolicy

Helper for making simplified policies that don't use the monadic context.

#limitRetries Source

limitRetries :: Int -> RetryPolicy

Retry immediately, but only up to @n@ times.

#limitRetriesByDelay Source

limitRetriesByDelay :: forall m d. Monad m => Duration d => d -> RetryPolicyM m -> RetryPolicyM m

Add an upperbound to a policy such that once the given time-delay amount per try has been reached or exceeded, the policy will stop retrying and fail. If you need to stop retrying once cumulative delay reaches a time-delay amount, use 'limitRetriesByCumulativeDelay'

#limitRetriesByCumulativeDelay Source

limitRetriesByCumulativeDelay :: forall m d. Monad m => Duration d => d -> RetryPolicyM m -> RetryPolicyM m

Add an upperbound to a policy such that once the cumulative delay over all retries has reached or exceeded the given limit, the policy will stop retrying and fail.

#constantDelay Source

constantDelay :: forall d. Duration d => d -> RetryPolicy

Cconstant delay with unlimited retries

#defaultRetryStatus Source

defaultRetryStatus :: RetryStatus

Initial, default retry status. Exported mostly to allow user code to test their handlers and retry policies. Use fields or lenses to update.

#applyPolicy Source

applyPolicy :: forall m fx. MonadAff fx m => RetryPolicyM m -> RetryStatus -> m (Maybe RetryStatus)

Apply policy on status to see what the decision would be. 'Nothing' implies no retry, 'Just' returns updated status.

#retrying Source

retrying :: forall b m fx. MonadAff fx m => RetryPolicyM m -> (RetryStatus -> b -> m Boolean) -> (RetryStatus -> m b) -> m b

Retry combinator for actions that don't raise exceptions, but signal in their type the outcome has failed. Examples are the 'Maybe', 'Either' and 'EitherT' monads.

#recovering Source

recovering :: forall a m fx. MonadAff fx m => MonadError Error m => RetryPolicyM m -> Array (RetryStatus -> Error -> m Boolean) -> (RetryStatus -> m a) -> m a

Run an action and recover from a raised exception by potentially retrying the action a number of times.