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

Add afix function (like mfix, but the value is passed as an awaitable)

parent 13842338
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,8 @@ module Quasar.Awaitable (
awaitableFromSTM,
-- * Awaitable helpers
afix,
afix_,
awaitSuccessOrFailure,
-- ** Awaiting multiple awaitables
......@@ -370,6 +371,22 @@ awaitSuccessOrFailure = await . fireAndForget . toAwaitable
fireAndForget :: MonadCatch m => m r -> m ()
fireAndForget x = void x `catchAll` const (pure ())
afix :: (MonadIO m, MonadCatch m) => (Awaitable a -> m a) -> m a
afix action = do
var <- newAsyncVar
catchAll
do
result <- action (toAwaitable var)
putAsyncVar_ var result
pure result
\ex -> do
failAsyncVar_ var ex
throwM ex
afix_ :: (MonadIO m, MonadCatch m) => (Awaitable a -> m a) -> m ()
afix_ = void . afix
-- ** Awaiting multiple awaitables
......
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