async-io-either 0.1.0.2 → 0.1.0.3
raw patch · 2 files changed
+27/−8 lines, 2 filesdep +retryPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependencies added: retry
API changes (from Hackage documentation)
+ Control.Concurrent.Async.Either: handleRetryE :: MonadIO m => RetryPolicyM IO -> (RetryStatus -> IO a) -> m (Either SomeException a)
+ Control.Concurrent.Async.Either: handleRetryToE :: MonadIO m => RetryPolicyM IO -> (RetryStatus -> IO a) -> (SomeException -> e) -> m (Either e a)
Files
async-io-either.cabal view
@@ -1,5 +1,5 @@ name: async-io-either-version: 0.1.0.2+version: 0.1.0.3 synopsis: Could be useful description: A way of running any IO type and capturing any exception, maybe, I think... homepage: https://github.com/mankyKitty/async-io-either#readme@@ -18,6 +18,7 @@ exposed-modules: Control.Concurrent.Async.Either build-depends: base >= 4.7 && < 5 , async > 0.2+ , retry , transformers default-language: Haskell2010
src/Control/Concurrent/Async/Either.hs view
@@ -1,11 +1,33 @@-{-# LANGUAGE CPP #-}+---------------------------+-- |+-- These functions are partially inspired by the 'Catching All Exceptions' blog <https://www.schoolofhaskell.com/user/snoyberg/general-haskell/exceptions/catching-all-exceptions post>+-- that explains a useful way of pushing off a (IO a) of a risky or smelly nature, and having it+-- provide a value indicating success or failure. This library does not go any further than taking+-- this result to a value, be it an exception or the desired result. You get an either, that's it.+--+-- It can be used where normally you might have to use @catch@ or similar mechanisms and you've already+-- built a @ExceptT@ having monad transformer stack in your application:+--+-- @+-- catch dangerous handleError+-- @+--+-- or if you've found yourself in the yucky position of having a @throw@ buried in your otherwise+-- pure code:+--+-- @+-- toMyError :: SomeException -> MyError+-- toMyError e = fromMaybe (throw e) <|> toMyError1 e <|> toMyError2 e+-- where+-- toMyError1 e' = Err1 <$> fromException e'+-- toMyError2 e' = Err2 <$> fromException e'+-- @+--------------------------- module Control.Concurrent.Async.Either ( runAsyncForE , runAsyncToE-#if VERSION_retry , handleRetryE , handleRetryToE-#endif ) where import qualified Control.Concurrent.Async as Async@@ -14,12 +36,9 @@ import Control.Exception (SomeException) import Data.Bifunctor (first) -#if VERSION_retry import Control.Retry (RetryPolicyM, RetryStatus, recoverAll)-#endif -#if VERSION_retry handleRetryE :: MonadIO m => RetryPolicyM IO@@ -36,7 +55,6 @@ -> m (Either e a) handleRetryToE rPolicy f eFn = runAsyncToE ( recoverAll rPolicy f ) eFn-#endif runAsyncForE :: MonadIO m