diff --git a/src/Quasar/Core.hs b/src/Quasar/Core.hs index f4764d1c9ff09edb65ae4e08040acceb39abb348..a92b890f6e80e7cd0c51f7fa10836d4203ec0a12 100644 --- a/src/Quasar/Core.hs +++ b/src/Quasar/Core.hs @@ -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