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

Add MonadFail constraint to MonadAwait

parent d97a1690
No related branches found
No related tags found
No related merge requests found
...@@ -59,7 +59,7 @@ import Data.Sequence ...@@ -59,7 +59,7 @@ import Data.Sequence
import Quasar.Prelude import Quasar.Prelude
class (MonadCatch m, MonadPlus m) => MonadAwait m where class (MonadCatch m, MonadFail m, MonadPlus m) => MonadAwait m where
-- | Wait until an awaitable is completed and then return it's value (or throw an exception). -- | Wait until an awaitable is completed and then return it's value (or throw an exception).
await :: IsAwaitable r a => a -> m r await :: IsAwaitable r a => a -> m r
...@@ -194,7 +194,7 @@ awaitableFromSTM :: forall m a. MonadIO m => STM a -> m (Awaitable a) ...@@ -194,7 +194,7 @@ awaitableFromSTM :: forall m a. MonadIO m => STM a -> m (Awaitable a)
awaitableFromSTM transaction = cacheAwaitable (unsafeAwaitSTM transaction :: Awaitable a) awaitableFromSTM transaction = cacheAwaitable (unsafeAwaitSTM transaction :: Awaitable a)
instance {-# OVERLAPS #-} (MonadCatch m, MonadPlus m) => MonadAwait (ReaderT (QueryFn m) m) where instance {-# OVERLAPS #-} (MonadCatch m, MonadFail m, MonadPlus m) => MonadAwait (ReaderT (QueryFn m) m) where
await = runAwaitable await = runAwaitable
unsafeAwaitSTM transaction = do unsafeAwaitSTM transaction = do
QueryFn querySTMFn <- ask QueryFn querySTMFn <- ask
...@@ -271,6 +271,9 @@ instance MonadCatch AwaitableStepM where ...@@ -271,6 +271,9 @@ instance MonadCatch AwaitableStepM where
catch result@(AwaitableFailed ex) handler = maybe result handler $ fromException ex catch result@(AwaitableFailed ex) handler = maybe result handler $ fromException ex
catch (AwaitableStep query next) handler = AwaitableStep query (\x -> next x `catch` handler) catch (AwaitableStep query next) handler = AwaitableStep query (\x -> next x `catch` handler)
instance MonadFail AwaitableStepM where
fail = throwM . userError
instance Alternative AwaitableStepM where instance Alternative AwaitableStepM where
x <|> y = x `catchAll` const y x <|> y = x `catchAll` const y
empty = throwM $ toException $ userError "empty" empty = throwM $ toException $ userError "empty"
......
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