Skip to content
Snippets Groups Projects
Commit 7a94a8d3 authored by Jens Nolte's avatar Jens Nolte
Browse files

Add exception channel for asynchronous exceptions


Co-authored-by: default avatarJan Beinke <git@janbeinke.com>
parent 65ac1e39
No related branches found
No related tags found
No related merge requests found
......@@ -89,6 +89,7 @@ library
Quasar.Async.Unmanaged
Quasar.Awaitable
Quasar.Disposable
Quasar.Exceptions
Quasar.Observable
Quasar.Observable.Delta
Quasar.Observable.ObservableHashMap
......
module Quasar.Exceptions (
ExceptionChannel(..),
throwToExceptionChannel,
catchInChannel,
catchAllInChannel,
) where
import Control.Concurrent.STM
import Control.Monad.Catch
import Quasar.Prelude
newtype ExceptionChannel = ExceptionChannel (SomeException -> STM ())
throwToExceptionChannel :: Exception e => ExceptionChannel -> e -> STM ()
throwToExceptionChannel (ExceptionChannel channelFn) ex = channelFn (toException ex)
-- TODO better name?
catchInChannel :: forall e. Exception e => (e -> STM ()) -> ExceptionChannel -> ExceptionChannel
catchInChannel handler parentChannel = ExceptionChannel $ mapM_ wrappedHandler . fromException
where
wrappedHandler :: e -> STM ()
wrappedHandler ex = catchAll (handler ex) (throwToExceptionChannel parentChannel)
catchAllInChannel :: (SomeException -> STM ()) -> ExceptionChannel -> ExceptionChannel
catchAllInChannel = catchInChannel
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment