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

Simplify `simpleAwaitable` signature

parent 744ca563
No related branches found
No related tags found
No related merge requests found
Pipeline #2398 failed
...@@ -113,8 +113,14 @@ successfulAwaitable = completedAwaitable . Right ...@@ -113,8 +113,14 @@ successfulAwaitable = completedAwaitable . Right
failedAwaitable :: SomeException -> Awaitable r failedAwaitable :: SomeException -> Awaitable r
failedAwaitable = completedAwaitable . Left failedAwaitable = completedAwaitable . Left
simpleAwaitable :: STM (Maybe (Either SomeException a)) -> Awaitable a -- | Create an awaitable from a `STM` transaction.
simpleAwaitable query = toAwaitable $ FnAwaitable $ querySTM query --
-- Use `retry` to signal that the awaitable is not yet completed and `throwM`/`throwSTM` to set the awaitable to failed.
simpleAwaitable :: STM a -> Awaitable a
simpleAwaitable query = toAwaitable $ FnAwaitable $ querySTM do
(Just . Right <$> query) `orElse` pure Nothing
`catchAll`
\ex -> pure (Just (Left ex))
mapAwaitable :: IsAwaitable i a => (Either SomeException i -> Either SomeException r) -> a -> Awaitable r mapAwaitable :: IsAwaitable i a => (Either SomeException i -> Either SomeException r) -> a -> Awaitable r
mapAwaitable fn awaitable = toAwaitable $ FnAwaitable $ fn <$> runAwaitable awaitable mapAwaitable fn awaitable = toAwaitable $ FnAwaitable $ fn <$> runAwaitable awaitable
......
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