From be5a29cc1954cdc45b269dc402df8a01f32c0697 Mon Sep 17 00:00:00 2001 From: Ian Duncan Date: Sun, 20 Oct 2019 20:34:34 +0900 Subject: [PATCH 1/2] Rename catchSync to catch, catch to catchAsync. --- src/Control/Effect/Catch.hs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Control/Effect/Catch.hs b/src/Control/Effect/Catch.hs index 06da8af..3120d8c 100644 --- a/src/Control/Effect/Catch.hs +++ b/src/Control/Effect/Catch.hs @@ -12,7 +12,7 @@ module Control.Effect.Catch ( Catch (..) , catch - , catchSync + , catchAsync ) where import Control.Carrier @@ -41,20 +41,22 @@ instance Effect Catch where -- Unhandled errors are rethrown. Use 'Exc.SomeException' if you want to catch all errors. -- -- | @since 0.1.0.0 -catch :: (Member Catch sig, Carrier sig m, Exc.Exception e) +catchAsync :: (Member Catch sig, Carrier sig m, Exc.Exception e) => m a -> (e -> m a) -> m a -catch go cleanup = send (CatchIO go cleanup pure) +catchAsync go cleanup = send (CatchIO go cleanup pure) --- | Like 'catch', but the handler only engages on synchronous exceptions. Async exceptions are rethrown. +-- | Like 'Control.Effect.Error.catchError', but delegating to 'Control.Exception.catch' under the hood, which allows catching errors that might occur when lifting 'IO' computations. Asynchronous exceptions are rethrown by this function. Use 'catchAsync' to catch them as well. +-- +-- Unhandled errors are rethrown. Use 'Exc.SomeException' if you want to catch all errors. -- -- | @since 0.1.0.0 -catchSync :: (Member Catch sig, Carrier sig m, Exc.Exception e, MonadIO m) +catch :: (Member Catch sig, Carrier sig m, Exc.Exception e, MonadIO m) => m a -> (e -> m a) -> m a -catchSync f g = f `catch` \e -> +catch f g = f `catch` \e -> if isSyncException e then g e -- intentionally rethrowing an async exception synchronously, From acb517b68a2178369167f7978e5043022b8bde35 Mon Sep 17 00:00:00 2001 From: Ian Duncan Date: Wed, 23 Oct 2019 10:21:00 +0900 Subject: [PATCH 2/2] Update changelog --- ChangeLog.md | 1 + src/Control/Effect/Catch.hs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index fa0c428..ac3261f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,6 +4,7 @@ * Add `Control.Effect.Resource` and `Control.Carrier.Resource`, as ported from fused-effects 0.5. * Add `Control.Carrier.State.IORef` to help people migrating from other state carriers. * Move `Control.Effect.Catch.CatchC` to `Control.Carrier.Catch` and simplify its internals. +* Rename `catch` to `catchAsync` and `catchSync` to `catch`. # 0.2.0.0 diff --git a/src/Control/Effect/Catch.hs b/src/Control/Effect/Catch.hs index 3120d8c..ca5b382 100644 --- a/src/Control/Effect/Catch.hs +++ b/src/Control/Effect/Catch.hs @@ -40,7 +40,7 @@ instance Effect Catch where -- -- Unhandled errors are rethrown. Use 'Exc.SomeException' if you want to catch all errors. -- --- | @since 0.1.0.0 +-- | @since 1.0.0.0 catchAsync :: (Member Catch sig, Carrier sig m, Exc.Exception e) => m a -> (e -> m a)