Package

purescript-aff-retry

Repository
Unisay/purescript-aff-retry
License
MIT
Uploaded by
jhrcek
Published on
2018-07-23T12:12:50Z

(Purescript port of Haskell's retry package)

Build Status

API docs on Pursuit

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.

Example usage

import Prelude

import Control.Monad.Aff (Aff, Milliseconds(..))
import Control.Monad.Aff.Console (CONSOLE, log)
import Control.Monad.Aff.Retry ( RetryPolicyM
                               , constantDelay
                               , defaultRetryStatus
                               , limitRetries
                               , recovering
                               )


someAction ::  x. Aff (console :: CONSOLE | x) Unit
someAction = log "Potentially failing action"

recoveredAction ::  x. Aff (console :: CONSOLE | x) Unit
recoveredAction = recovering myRetryPolicy checks someAction
  where
    myRetryPolicy ::  x. RetryPolicyM (Aff x)
    myRetryPolicy = constantDelay (Milliseconds 200.0) <> limitRetries 10

    checks ::  x. Array (RetryStatus -> Error -> Aff x Boolean)
    checks = [\(RetryStatus { iterNumber: n }) -> error -> pure true ]