Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 1.3 KB

README.md

File metadata and controls

40 lines (27 loc) · 1.3 KB

purescript-aff-retry

(Purescript port of Haskell's retry package)

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 ]