Package

purescript-aff-retry

Repository
Unisay/purescript-aff-retry
License
MIT
Uploaded by
i-am-the-slime
Published on
2022-05-19T12:27:02Z

(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 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 ]