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

Add Async utilities

parent 9859bde5
No related branches found
No related tags found
No related merge requests found
Pipeline #2326 passed
......@@ -11,6 +11,10 @@ module Quasar.Core (
async,
await,
runAsyncIO,
awaitResult,
-- * Async helpers
mapAsync,
-- * AsyncVar
AsyncVar,
......@@ -72,7 +76,6 @@ class IsAsync r a | a -> r where
toAsync = SomeAsync
data Async r = forall a. IsAsync r a => SomeAsync a
instance IsAsync r (Async r) where
......@@ -141,6 +144,16 @@ await = AsyncIO . pure . toAsync
runAsyncIO :: AsyncIO r -> IO r
runAsyncIO = async >=> wait
awaitResult :: AsyncIO (Async r) -> AsyncIO r
awaitResult = (await =<<)
mapAsync :: (a -> b) -> Async a -> AsyncIO (Async b)
-- FIXME: don't actually attach a function if the resulting async is not used
-- maybe use `Weak`? When `Async b` is GC'ed, the handler is detached from `Async a`
mapAsync fn = async . fmap fn . await
-- ** Forking asyncs
......
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