(Purescript port of Haskell's retry package)
Monadic action combinators that add delayed-retry functionality, potentially with exponential-backoff, to arbitrary actions.
The main purpose of this package is to make it easy to work reliably with MonadAff
actions that often fail. Common examples are database queries and large file uploads.
import Prelude
import Effect.Aff (Aff, Milliseconds(..))
import Effect.Console (log)
import Effect.Class (liftEffect)
import Effect.Aff.Retry ( RetryPolicyM
, constantDelay
, defaultRetryStatus
, limitRetries
, recovering
)
someAction :: Aff Unit
someAction = liftEffect $ log "Potentially failing action"
recoveredAction :: Aff Unit
recoveredAction = recovering myRetryPolicy checks someAction
where
myRetryPolicy :: RetryPolicyM Aff
myRetryPolicy = constantDelay (Milliseconds 200.0) <> limitRetries 10
checks :: Array (RetryStatus -> Error -> Aff Boolean)
checks = [\(RetryStatus { iterNumber: n }) -> error -> pure true ]