Module

Yoga.Om.Retry

Package
purescript-yoga-om
Repository
rowtype-yoga/purescript-yoga-om

#recovering Source

recovering :: forall ctx err rest a (handlersRL :: RowList Type) (handlers :: Row Type) (handled :: Row Type). RowToList handlers handlersRL => VariantMatchCases handlersRL handled (Om ctx err Boolean) => Union handled rest (exception :: Error | err) => RetryPolicyM (Om ctx err) -> (RetryStatus -> Record handlers) -> (RetryStatus -> Om ctx err a) -> Om ctx err a

#repeating Source

repeating :: forall ctx err a. RetryPolicyM (Om ctx err) -> (RetryStatus -> a -> Om ctx err Boolean) -> (RetryStatus -> Om ctx err a) -> Om ctx err a

Repeat a successful action according to a policy while a condition holds. Returns the last result.

repeating (constantDelay (Milliseconds 1000.0) <> limitRetries 10)
  (\_ result -> pure (result < threshold))
  (\_ -> pollSensor)

Re-exports from Effect.Aff.Retry

#RetryStatus Source

newtype RetryStatus

Datatype with stats about retries made thus far

Instances

#RetryPolicyM Source

newtype RetryPolicyM :: (Type -> Type) -> Typenewtype 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'.

Instances

#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.

#applyAndDelay Source

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

Apply policy and delay by its amount if it results in a retry. Returns updated status.