@@ -34,6 +34,8 @@ module Asyncly.AsyncT
35 , thenDiscard
35 , thenDiscard
38 -- internal
40 -- internal
@@ -603,31 +605,22 @@ instance (Num a, Monad (AsyncT m)) => Num (AsyncT m a) where
603-- Special compositions
605-- Special compositions
604------------------------------------------------------------------------------
606------------------------------------------------------------------------------
606−infixr 1 >>*, *>>
608+infixr 1 >>*, *>>, >>|
608−{-
610+-- XXX This can be moved to utility functions as it is purely app level
609-- | Run @b@ once, discarding its result when the first task in task set @a@
611-- | Run @b@ once, discarding its result when the first task in task set @a@
610-- has finished. Useful to start a singleton task after the first task has been
612-- has finished. Useful to start a singleton task after the first task has been
612−afterFirst :: MonadIO m => AsyncT m a -> AsyncT m b -> AsyncT m a
614+afterFirst :: MonadAsync m => AsyncT m a -> AsyncT m b -> AsyncT m a
613−afterFirst ma mb = AsyncT $ do
615+afterFirst ma mb = do
614− fs <- getContinuations
615− ref <- liftIO $ newIORef False
616+ ref <- liftIO $ newIORef False
616− setContinuation ma (cont ref) fs
617+ x <- ma
620− where cont ref x = AsyncT $ do
621− n <- liftIO $ readIORef ref
618+ done <- liftIO $ readIORef ref
623− then return $ Just x
624− else do liftIO $ writeIORef ref True
619+ when (not done) $ (liftIO $ writeIORef ref True) >>* mb
626− return $ Just x
620+ return x
628−(<|) :: MonadIO m => AsyncT m a -> AsyncT m b -> AsyncT m a
622+(>>|) :: MonadAsync m => AsyncT m a -> AsyncT m b -> AsyncT m a
629−(<|) = afterFirst
623+(>>|) = afterFirst
632-- | Run 'm a' in "isolation" and discard its result, and then run 'm b' and
625-- | Run 'm a' in "isolation" and discard its result, and then run 'm b' and
633-- return its result. Isolation means that any alternative actions inside 'm
626-- return its result. Isolation means that any alternative actions inside 'm