{-# LANGUAGE DerivingVia #-}
module Control.Effect.Conc
(
Conc
, Async
, concToIO
, concToUnliftIO
, async
, withAsync
, wait
, poll
, concurrently
, race
, waitEither
, waitBoth
, link
, link2
, waitAny
, mapConcurrently
, forConcurrently
, Concurrently(..)
, asyncBound
, asyncOn
, asyncWithUnmask
, asyncOnWithUnmask
, withAsyncBound
, withAsyncWithUnmask
, withAsyncOnWithUnmask
, waitCatch
, cancel
, uninterruptibleCancel
, cancelWith
, waitAnyCatch
, waitAnyCancel
, waitAnyCatchCancel
, waitEitherCatch
, waitEitherCancel
, waitEitherCatchCancel
, waitEither_
, linkOnly
, link2Only
, race_
, concurrently_
, mapConcurrently_
, forConcurrently_
, replicateConcurrently
, replicateConcurrently_
, A.asyncThreadId
, A.AsyncCancelled(..)
, A.ExceptionInLinkedThread(..)
, A.waitAnySTM
, A.waitAnyCatchSTM
, A.waitEitherSTM
, A.waitEitherCatchSTM
, A.waitEitherSTM_
, A.waitBothSTM
, A.compareAsyncs
, ConcToIOC
, ConcToUnliftIOC
) where
import Control.Applicative
import Control.Monad
import Control.Concurrent.Async (Async)
import qualified Control.Concurrent.Async as A
import Control.Effect
import Control.Effect.Unlift
import Control.Exception (SomeException, Exception)
import Control.Effect.Internal.Newtype
import Control.Effect.Internal.Utils
import Control.Monad.Trans.Identity
import Control.Effect.Carrier.Internal.Compose
import Control.Effect.Carrier.Internal.Interpret
newtype Conc m a = Conc (Unlift IO m a)
deriving Conc z x -> UnwrappedEff Conc z x
(forall (z :: * -> *) x. Conc z x -> UnwrappedEff Conc z x)
-> EffNewtype Conc
forall (z :: * -> *) x. Conc z x -> UnwrappedEff Conc z x
forall (e :: Effect).
(forall (z :: * -> *) x. e z x -> UnwrappedEff e z x)
-> EffNewtype e
unwrapped :: Conc z x -> UnwrappedEff Conc z x
$cunwrapped :: forall (z :: * -> *) x. Conc z x -> UnwrappedEff Conc z x
EffNewtype via Conc `WrapperOf` Unlift IO
unliftConc :: Eff Conc m => ((forall x. m x -> IO x) -> IO a) -> m a
unliftConc :: ((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (forall x. m x -> IO x) -> IO a
main = (Unlift IO Any Any -> Conc Any Any)
-> WrapC (Unlift IO) Conc m a -> m a
forall (e :: Effect) (m :: * -> *) (unwrappedE :: Effect)
(z :: * -> *) x a.
(Member e (Derivs m), Carrier m, Coercible unwrappedE e) =>
(unwrappedE z x -> e z x) -> WrapC unwrappedE e m a -> m a
wrapWith Unlift IO Any Any -> Conc Any Any
forall (m :: * -> *) a. Unlift IO m a -> Conc m a
Conc (WrapC (Unlift IO) Conc m a -> m a)
-> WrapC (Unlift IO) Conc m a -> m a
forall a b. (a -> b) -> a -> b
$ ((forall x. WrapC (Unlift IO) Conc m x -> IO x) -> IO a)
-> WrapC (Unlift IO) Conc m a
forall (b :: * -> *) (m :: * -> *) a.
Eff (Unlift b) m =>
((forall x. m x -> b x) -> b a) -> m a
unlift (\forall x. WrapC (Unlift IO) Conc m x -> IO x
lower -> (forall x. m x -> IO x) -> IO a
main (WrapC (Unlift IO) Conc m x -> IO x
forall x. WrapC (Unlift IO) Conc m x -> IO x
lower (WrapC (Unlift IO) Conc m x -> IO x)
-> (m x -> WrapC (Unlift IO) Conc m x) -> m x -> IO x
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# m x -> WrapC (Unlift IO) Conc m x
forall (t :: Effect) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift))
{-# INLINE unliftConc #-}
type ConcToIOC = CompositionC
'[ UnwrapTopC Conc
, UnliftToFinalC IO
]
type ConcToUnliftIOC = UnwrapC Conc
concToIO :: ( Carrier m
, MonadBaseControlPure IO m
)
=> ConcToIOC m a
-> m a
concToIO :: ConcToIOC m a -> m a
concToIO =
UnliftToFinalC IO m a -> m a
forall (b :: * -> *) (m :: * -> *) a.
(MonadBaseControlPure b m, Carrier m) =>
UnliftToFinalC b m a -> m a
unliftToFinal
(UnliftToFinalC IO m a -> m a)
-> (UnwrapTopC Conc (InterpretPrimC UnliftToFinalH (Unlift IO) m) a
-> UnliftToFinalC IO m a)
-> UnwrapTopC Conc (InterpretPrimC UnliftToFinalH (Unlift IO) m) a
-> m a
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# UnwrapTopC Conc (InterpretPrimC UnliftToFinalH (Unlift IO) m) a
-> UnliftToFinalC IO m a
forall (e :: Effect) (m :: * -> *) a.
(HeadEff (UnwrappedEff e) m, EffNewtype e, Carrier m) =>
UnwrapTopC e m a -> m a
unwrapTop
(UnwrapTopC Conc (InterpretPrimC UnliftToFinalH (Unlift IO) m) a
-> m a)
-> (ConcToIOC m a
-> UnwrapTopC Conc (InterpretPrimC UnliftToFinalH (Unlift IO) m) a)
-> ConcToIOC m a
-> m a
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# ConcToIOC m a
-> UnwrapTopC Conc (InterpretPrimC UnliftToFinalH (Unlift IO) m) a
forall (ts :: [Effect]) (m :: * -> *) a.
CompositionC ts m a -> CompositionBaseM ts m a
runComposition
{-# INLINE concToIO #-}
concToUnliftIO :: Eff (Unlift IO) m
=> ConcToUnliftIOC m a
-> m a
concToUnliftIO :: ConcToUnliftIOC m a -> m a
concToUnliftIO = ConcToUnliftIOC m a -> m a
forall (e :: Effect) (m :: * -> *) a.
(Carrier m, Member (UnwrappedEff e) (Derivs m), EffNewtype e) =>
UnwrapC e m a -> m a
unwrap
{-# INLINE concToUnliftIO #-}
async :: Eff Conc m => m a -> m (Async a)
async :: m a -> m (Async a)
async m a
m = ((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a))
-> ((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower -> IO a -> IO (Async a)
forall a. IO a -> IO (Async a)
A.async (m a -> IO a
forall x. m x -> IO x
lower m a
m)
{-# INLINE async #-}
asyncBound :: Eff Conc m => m a -> m (Async a)
asyncBound :: m a -> m (Async a)
asyncBound m a
m = ((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a))
-> ((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower -> IO a -> IO (Async a)
forall a. IO a -> IO (Async a)
A.asyncBound (m a -> IO a
forall x. m x -> IO x
lower m a
m)
{-# INLINE asyncBound #-}
asyncOn :: Eff Conc m => Int -> m a -> m (Async a)
asyncOn :: Int -> m a -> m (Async a)
asyncOn Int
i m a
m = ((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a))
-> ((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower -> Int -> IO a -> IO (Async a)
forall a. Int -> IO a -> IO (Async a)
A.asyncOn Int
i (m a -> IO a
forall x. m x -> IO x
lower m a
m)
{-# INLINE asyncOn #-}
asyncWithUnmask :: Eff Conc m => ((forall x. m x -> m x) -> m a) -> m (Async a)
asyncWithUnmask :: ((forall x. m x -> m x) -> m a) -> m (Async a)
asyncWithUnmask (forall x. m x -> m x) -> m a
main = ((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a))
-> ((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower -> ((forall b. IO b -> IO b) -> IO a) -> IO (Async a)
forall a. ((forall b. IO b -> IO b) -> IO a) -> IO (Async a)
A.asyncWithUnmask (((forall b. IO b -> IO b) -> IO a) -> IO (Async a))
-> ((forall b. IO b -> IO b) -> IO a) -> IO (Async a)
forall a b. (a -> b) -> a -> b
$ \forall b. IO b -> IO b
restore ->
m a -> IO a
forall x. m x -> IO x
lower (m a -> IO a) -> m a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall x. m x -> m x) -> m a
main ((forall x. m x -> m x) -> m a) -> (forall x. m x -> m x) -> m a
forall a b. (a -> b) -> a -> b
$ \m x
m -> ((forall x. m x -> IO x) -> IO x) -> m x
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO x) -> m x)
-> ((forall x. m x -> IO x) -> IO x) -> m x
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower' -> IO x -> IO x
forall b. IO b -> IO b
restore (m x -> IO x
forall x. m x -> IO x
lower' m x
m)
{-# INLINE asyncWithUnmask #-}
asyncOnWithUnmask :: Eff Conc m => Int -> ((forall x. m x -> m x) -> m a) -> m (Async a)
asyncOnWithUnmask :: Int -> ((forall x. m x -> m x) -> m a) -> m (Async a)
asyncOnWithUnmask Int
i (forall x. m x -> m x) -> m a
main = ((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a))
-> ((forall x. m x -> IO x) -> IO (Async a)) -> m (Async a)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower -> Int -> ((forall b. IO b -> IO b) -> IO a) -> IO (Async a)
forall a. Int -> ((forall b. IO b -> IO b) -> IO a) -> IO (Async a)
A.asyncOnWithUnmask Int
i (((forall b. IO b -> IO b) -> IO a) -> IO (Async a))
-> ((forall b. IO b -> IO b) -> IO a) -> IO (Async a)
forall a b. (a -> b) -> a -> b
$ \forall b. IO b -> IO b
restore ->
m a -> IO a
forall x. m x -> IO x
lower (m a -> IO a) -> m a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall x. m x -> m x) -> m a
main ((forall x. m x -> m x) -> m a) -> (forall x. m x -> m x) -> m a
forall a b. (a -> b) -> a -> b
$ \m x
m -> ((forall x. m x -> IO x) -> IO x) -> m x
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO x) -> m x)
-> ((forall x. m x -> IO x) -> IO x) -> m x
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower' -> IO x -> IO x
forall b. IO b -> IO b
restore (m x -> IO x
forall x. m x -> IO x
lower' m x
m)
{-# INLINE asyncOnWithUnmask #-}
withAsync :: Eff Conc m => m a -> (Async a -> m b) -> m b
withAsync :: m a -> (Async a -> m b) -> m b
withAsync m a
m Async a -> m b
c = ((forall x. m x -> IO x) -> IO b) -> m b
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO b) -> m b)
-> ((forall x. m x -> IO x) -> IO b) -> m b
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower -> IO a -> (Async a -> IO b) -> IO b
forall a b. IO a -> (Async a -> IO b) -> IO b
A.withAsync (m a -> IO a
forall x. m x -> IO x
lower m a
m) (m b -> IO b
forall x. m x -> IO x
lower (m b -> IO b) -> (Async a -> m b) -> Async a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Async a -> m b
c)
{-# INLINE withAsync #-}
withAsyncBound :: Eff Conc m => m a -> (Async a -> m b) -> m b
withAsyncBound :: m a -> (Async a -> m b) -> m b
withAsyncBound m a
m Async a -> m b
c = ((forall x. m x -> IO x) -> IO b) -> m b
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO b) -> m b)
-> ((forall x. m x -> IO x) -> IO b) -> m b
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower -> IO a -> (Async a -> IO b) -> IO b
forall a b. IO a -> (Async a -> IO b) -> IO b
A.withAsyncBound (m a -> IO a
forall x. m x -> IO x
lower m a
m) (m b -> IO b
forall x. m x -> IO x
lower (m b -> IO b) -> (Async a -> m b) -> Async a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Async a -> m b
c)
{-# INLINE withAsyncBound #-}
withAsyncWithUnmask :: Eff Conc m => ((forall x. m x -> m x) -> m a) -> (Async a -> m b) -> m b
withAsyncWithUnmask :: ((forall x. m x -> m x) -> m a) -> (Async a -> m b) -> m b
withAsyncWithUnmask (forall x. m x -> m x) -> m a
main Async a -> m b
c = ((forall x. m x -> IO x) -> IO b) -> m b
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO b) -> m b)
-> ((forall x. m x -> IO x) -> IO b) -> m b
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower ->
((forall b. IO b -> IO b) -> IO a) -> (Async a -> IO b) -> IO b
forall a b.
((forall b. IO b -> IO b) -> IO a) -> (Async a -> IO b) -> IO b
A.withAsyncWithUnmask
(\forall b. IO b -> IO b
restore -> m a -> IO a
forall x. m x -> IO x
lower (m a -> IO a) -> m a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall x. m x -> m x) -> m a
main ((forall x. m x -> m x) -> m a) -> (forall x. m x -> m x) -> m a
forall a b. (a -> b) -> a -> b
$ \m x
m -> ((forall x. m x -> IO x) -> IO x) -> m x
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO x) -> m x)
-> ((forall x. m x -> IO x) -> IO x) -> m x
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower' -> IO x -> IO x
forall b. IO b -> IO b
restore (m x -> IO x
forall x. m x -> IO x
lower' m x
m))
(m b -> IO b
forall x. m x -> IO x
lower (m b -> IO b) -> (Async a -> m b) -> Async a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Async a -> m b
c)
{-# INLINE withAsyncWithUnmask #-}
withAsyncOnWithUnmask :: Eff Conc m => Int -> ((forall x. m x -> m x) -> m a) -> (Async a -> m b) -> m b
withAsyncOnWithUnmask :: Int -> ((forall x. m x -> m x) -> m a) -> (Async a -> m b) -> m b
withAsyncOnWithUnmask Int
i (forall x. m x -> m x) -> m a
main Async a -> m b
c = ((forall x. m x -> IO x) -> IO b) -> m b
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO b) -> m b)
-> ((forall x. m x -> IO x) -> IO b) -> m b
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower ->
Int
-> ((forall b. IO b -> IO b) -> IO a) -> (Async a -> IO b) -> IO b
forall a b.
Int
-> ((forall b. IO b -> IO b) -> IO a) -> (Async a -> IO b) -> IO b
A.withAsyncOnWithUnmask Int
i
(\forall b. IO b -> IO b
restore -> m a -> IO a
forall x. m x -> IO x
lower (m a -> IO a) -> m a -> IO a
forall a b. (a -> b) -> a -> b
$ (forall x. m x -> m x) -> m a
main ((forall x. m x -> m x) -> m a) -> (forall x. m x -> m x) -> m a
forall a b. (a -> b) -> a -> b
$ \m x
m -> ((forall x. m x -> IO x) -> IO x) -> m x
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO x) -> m x)
-> ((forall x. m x -> IO x) -> IO x) -> m x
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower' -> IO x -> IO x
forall b. IO b -> IO b
restore (m x -> IO x
forall x. m x -> IO x
lower' m x
m))
(m b -> IO b
forall x. m x -> IO x
lower (m b -> IO b) -> (Async a -> m b) -> Async a -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Async a -> m b
c)
{-# INLINE withAsyncOnWithUnmask #-}
wait :: Eff Conc m => Async a -> m a
wait :: Async a -> m a
wait Async a
a = ((forall x. m x -> IO x) -> IO a) -> m a
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO a) -> m a)
-> ((forall x. m x -> IO x) -> IO a) -> m a
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a -> IO a
forall a. Async a -> IO a
A.wait Async a
a
{-# INLINE wait #-}
poll :: Eff Conc m => Async a -> m (Maybe (Either SomeException a))
poll :: Async a -> m (Maybe (Either SomeException a))
poll Async a
a = ((forall x. m x -> IO x) -> IO (Maybe (Either SomeException a)))
-> m (Maybe (Either SomeException a))
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Maybe (Either SomeException a)))
-> m (Maybe (Either SomeException a)))
-> ((forall x. m x -> IO x) -> IO (Maybe (Either SomeException a)))
-> m (Maybe (Either SomeException a))
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a -> IO (Maybe (Either SomeException a))
forall a. Async a -> IO (Maybe (Either SomeException a))
A.poll Async a
a
{-# INLINE poll #-}
waitCatch :: Eff Conc m => Async a -> m (Either SomeException a)
waitCatch :: Async a -> m (Either SomeException a)
waitCatch Async a
a = ((forall x. m x -> IO x) -> IO (Either SomeException a))
-> m (Either SomeException a)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Either SomeException a))
-> m (Either SomeException a))
-> ((forall x. m x -> IO x) -> IO (Either SomeException a))
-> m (Either SomeException a)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a -> IO (Either SomeException a)
forall a. Async a -> IO (Either SomeException a)
A.waitCatch Async a
a
{-# INLINE waitCatch #-}
cancel :: Eff Conc m => Async a -> m ()
cancel :: Async a -> m ()
cancel Async a
a = ((forall x. m x -> IO x) -> IO ()) -> m ()
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO ()) -> m ())
-> ((forall x. m x -> IO x) -> IO ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a -> IO ()
forall a. Async a -> IO ()
A.cancel Async a
a
{-# INLINE cancel #-}
uninterruptibleCancel :: Eff Conc m => Async a -> m ()
uninterruptibleCancel :: Async a -> m ()
uninterruptibleCancel Async a
a = ((forall x. m x -> IO x) -> IO ()) -> m ()
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO ()) -> m ())
-> ((forall x. m x -> IO x) -> IO ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a -> IO ()
forall a. Async a -> IO ()
A.uninterruptibleCancel Async a
a
{-# INLINE uninterruptibleCancel #-}
cancelWith :: Eff Conc m => (Exception e, Eff Conc m) => Async a -> e -> m ()
cancelWith :: Async a -> e -> m ()
cancelWith Async a
a e
e = ((forall x. m x -> IO x) -> IO ()) -> m ()
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO ()) -> m ())
-> ((forall x. m x -> IO x) -> IO ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a -> e -> IO ()
forall e a. Exception e => Async a -> e -> IO ()
A.cancelWith Async a
a e
e
{-# INLINE cancelWith #-}
waitAny :: Eff Conc m => [Async a] -> m (Async a, a)
waitAny :: [Async a] -> m (Async a, a)
waitAny [Async a]
as = ((forall x. m x -> IO x) -> IO (Async a, a)) -> m (Async a, a)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Async a, a)) -> m (Async a, a))
-> ((forall x. m x -> IO x) -> IO (Async a, a)) -> m (Async a, a)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> [Async a] -> IO (Async a, a)
forall a. [Async a] -> IO (Async a, a)
A.waitAny [Async a]
as
{-# INLINE waitAny #-}
waitAnyCatch :: Eff Conc m => [Async a] -> m (Async a, Either SomeException a)
waitAnyCatch :: [Async a] -> m (Async a, Either SomeException a)
waitAnyCatch [Async a]
as = ((forall x. m x -> IO x) -> IO (Async a, Either SomeException a))
-> m (Async a, Either SomeException a)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Async a, Either SomeException a))
-> m (Async a, Either SomeException a))
-> ((forall x. m x -> IO x)
-> IO (Async a, Either SomeException a))
-> m (Async a, Either SomeException a)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> [Async a] -> IO (Async a, Either SomeException a)
forall a. [Async a] -> IO (Async a, Either SomeException a)
A.waitAnyCatch [Async a]
as
{-# INLINE waitAnyCatch #-}
waitAnyCancel :: Eff Conc m => [Async a] -> m (Async a, a)
waitAnyCancel :: [Async a] -> m (Async a, a)
waitAnyCancel [Async a]
as = ((forall x. m x -> IO x) -> IO (Async a, a)) -> m (Async a, a)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Async a, a)) -> m (Async a, a))
-> ((forall x. m x -> IO x) -> IO (Async a, a)) -> m (Async a, a)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> [Async a] -> IO (Async a, a)
forall a. [Async a] -> IO (Async a, a)
A.waitAnyCancel [Async a]
as
{-# INLINE waitAnyCancel #-}
waitAnyCatchCancel :: Eff Conc m => [Async a] -> m (Async a, Either SomeException a)
waitAnyCatchCancel :: [Async a] -> m (Async a, Either SomeException a)
waitAnyCatchCancel [Async a]
as = ((forall x. m x -> IO x) -> IO (Async a, Either SomeException a))
-> m (Async a, Either SomeException a)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Async a, Either SomeException a))
-> m (Async a, Either SomeException a))
-> ((forall x. m x -> IO x)
-> IO (Async a, Either SomeException a))
-> m (Async a, Either SomeException a)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> [Async a] -> IO (Async a, Either SomeException a)
forall a. [Async a] -> IO (Async a, Either SomeException a)
A.waitAnyCatchCancel [Async a]
as
{-# INLINE waitAnyCatchCancel #-}
waitEither :: Eff Conc m => Async a -> Async b -> m (Either a b)
waitEither :: Async a -> Async b -> m (Either a b)
waitEither Async a
aa Async b
ab = ((forall x. m x -> IO x) -> IO (Either a b)) -> m (Either a b)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Either a b)) -> m (Either a b))
-> ((forall x. m x -> IO x) -> IO (Either a b)) -> m (Either a b)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a -> Async b -> IO (Either a b)
forall a b. Async a -> Async b -> IO (Either a b)
A.waitEither Async a
aa Async b
ab
{-# INLINE waitEither #-}
waitEitherCatch :: Eff Conc m => Async a -> Async b -> m (Either (Either SomeException a) (Either SomeException b))
waitEitherCatch :: Async a
-> Async b
-> m (Either (Either SomeException a) (Either SomeException b))
waitEitherCatch Async a
aa Async b
ab = ((forall x. m x -> IO x)
-> IO (Either (Either SomeException a) (Either SomeException b)))
-> m (Either (Either SomeException a) (Either SomeException b))
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x)
-> IO (Either (Either SomeException a) (Either SomeException b)))
-> m (Either (Either SomeException a) (Either SomeException b)))
-> ((forall x. m x -> IO x)
-> IO (Either (Either SomeException a) (Either SomeException b)))
-> m (Either (Either SomeException a) (Either SomeException b))
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a
-> Async b
-> IO (Either (Either SomeException a) (Either SomeException b))
forall a b.
Async a
-> Async b
-> IO (Either (Either SomeException a) (Either SomeException b))
A.waitEitherCatch Async a
aa Async b
ab
{-# INLINE waitEitherCatch #-}
waitEitherCancel :: Eff Conc m => Async a -> Async b -> m (Either a b)
waitEitherCancel :: Async a -> Async b -> m (Either a b)
waitEitherCancel Async a
aa Async b
ab = ((forall x. m x -> IO x) -> IO (Either a b)) -> m (Either a b)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Either a b)) -> m (Either a b))
-> ((forall x. m x -> IO x) -> IO (Either a b)) -> m (Either a b)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a -> Async b -> IO (Either a b)
forall a b. Async a -> Async b -> IO (Either a b)
A.waitEitherCancel Async a
aa Async b
ab
{-# INLINE waitEitherCancel #-}
waitEitherCatchCancel :: Eff Conc m => Async a -> Async b -> m (Either (Either SomeException a) (Either SomeException b))
waitEitherCatchCancel :: Async a
-> Async b
-> m (Either (Either SomeException a) (Either SomeException b))
waitEitherCatchCancel Async a
aa Async b
ab = ((forall x. m x -> IO x)
-> IO (Either (Either SomeException a) (Either SomeException b)))
-> m (Either (Either SomeException a) (Either SomeException b))
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x)
-> IO (Either (Either SomeException a) (Either SomeException b)))
-> m (Either (Either SomeException a) (Either SomeException b)))
-> ((forall x. m x -> IO x)
-> IO (Either (Either SomeException a) (Either SomeException b)))
-> m (Either (Either SomeException a) (Either SomeException b))
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a
-> Async b
-> IO (Either (Either SomeException a) (Either SomeException b))
forall a b.
Async a
-> Async b
-> IO (Either (Either SomeException a) (Either SomeException b))
A.waitEitherCatchCancel Async a
aa Async b
ab
{-# INLINE waitEitherCatchCancel #-}
waitEither_ :: Eff Conc m => Async a -> Async b -> m ()
waitEither_ :: Async a -> Async b -> m ()
waitEither_ Async a
aa Async b
ab = ((forall x. m x -> IO x) -> IO ()) -> m ()
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO ()) -> m ())
-> ((forall x. m x -> IO x) -> IO ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a -> Async b -> IO ()
forall a b. Async a -> Async b -> IO ()
A.waitEither_ Async a
aa Async b
ab
{-# INLINE waitEither_ #-}
waitBoth :: Eff Conc m => Async a -> Async b -> m (a, b)
waitBoth :: Async a -> Async b -> m (a, b)
waitBoth Async a
aa Async b
ab = ((forall x. m x -> IO x) -> IO (a, b)) -> m (a, b)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (a, b)) -> m (a, b))
-> ((forall x. m x -> IO x) -> IO (a, b)) -> m (a, b)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a -> Async b -> IO (a, b)
forall a b. Async a -> Async b -> IO (a, b)
A.waitBoth Async a
aa Async b
ab
{-# INLINE waitBoth #-}
link :: Eff Conc m => Async a -> m ()
link :: Async a -> m ()
link Async a
a = ((forall x. m x -> IO x) -> IO ()) -> m ()
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO ()) -> m ())
-> ((forall x. m x -> IO x) -> IO ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a -> IO ()
forall a. Async a -> IO ()
A.link Async a
a
{-# INLINE link #-}
linkOnly :: Eff Conc m => (SomeException -> Bool) -> Async a -> m ()
linkOnly :: (SomeException -> Bool) -> Async a -> m ()
linkOnly SomeException -> Bool
h Async a
a = ((forall x. m x -> IO x) -> IO ()) -> m ()
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO ()) -> m ())
-> ((forall x. m x -> IO x) -> IO ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> (SomeException -> Bool) -> Async a -> IO ()
forall a. (SomeException -> Bool) -> Async a -> IO ()
A.linkOnly SomeException -> Bool
h Async a
a
{-# INLINE linkOnly #-}
link2 :: Eff Conc m => Async a -> Async b -> m ()
link2 :: Async a -> Async b -> m ()
link2 Async a
a Async b
b = ((forall x. m x -> IO x) -> IO ()) -> m ()
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO ()) -> m ())
-> ((forall x. m x -> IO x) -> IO ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Async a -> Async b -> IO ()
forall a b. Async a -> Async b -> IO ()
A.link2 Async a
a Async b
b
{-# INLINE link2 #-}
link2Only :: Eff Conc m => (SomeException -> Bool) -> Async a -> Async b -> m ()
link2Only :: (SomeException -> Bool) -> Async a -> Async b -> m ()
link2Only SomeException -> Bool
h Async a
a Async b
b = ((forall x. m x -> IO x) -> IO ()) -> m ()
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO ()) -> m ())
-> ((forall x. m x -> IO x) -> IO ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> (SomeException -> Bool) -> Async a -> Async b -> IO ()
forall a b. (SomeException -> Bool) -> Async a -> Async b -> IO ()
A.link2Only SomeException -> Bool
h Async a
a Async b
b
{-# INLINE link2Only #-}
race :: Eff Conc m => m a -> m b -> m (Either a b)
race :: m a -> m b -> m (Either a b)
race m a
ma m b
mb = ((forall x. m x -> IO x) -> IO (Either a b)) -> m (Either a b)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (Either a b)) -> m (Either a b))
-> ((forall x. m x -> IO x) -> IO (Either a b)) -> m (Either a b)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower -> IO a -> IO b -> IO (Either a b)
forall a b. IO a -> IO b -> IO (Either a b)
A.race (m a -> IO a
forall x. m x -> IO x
lower m a
ma) (m b -> IO b
forall x. m x -> IO x
lower m b
mb)
{-# INLINE race #-}
race_ :: Eff Conc m => m a -> m b -> m ()
race_ :: m a -> m b -> m ()
race_ m a
ma m b
mb = ((forall x. m x -> IO x) -> IO ()) -> m ()
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO ()) -> m ())
-> ((forall x. m x -> IO x) -> IO ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower -> IO a -> IO b -> IO ()
forall a b. IO a -> IO b -> IO ()
A.race_ (m a -> IO a
forall x. m x -> IO x
lower m a
ma) (m b -> IO b
forall x. m x -> IO x
lower m b
mb)
{-# INLINE race_ #-}
concurrently :: Eff Conc m => m a -> m b -> m (a, b)
concurrently :: m a -> m b -> m (a, b)
concurrently m a
ma m b
mb = ((forall x. m x -> IO x) -> IO (a, b)) -> m (a, b)
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO (a, b)) -> m (a, b))
-> ((forall x. m x -> IO x) -> IO (a, b)) -> m (a, b)
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower -> IO a -> IO b -> IO (a, b)
forall a b. IO a -> IO b -> IO (a, b)
A.concurrently (m a -> IO a
forall x. m x -> IO x
lower m a
ma) (m b -> IO b
forall x. m x -> IO x
lower m b
mb)
{-# INLINE concurrently #-}
concurrently_ :: Eff Conc m => m a -> m b -> m ()
concurrently_ :: m a -> m b -> m ()
concurrently_ m a
ma m b
mb = ((forall x. m x -> IO x) -> IO ()) -> m ()
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO ()) -> m ())
-> ((forall x. m x -> IO x) -> IO ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower -> IO a -> IO b -> IO ()
forall a b. IO a -> IO b -> IO ()
A.concurrently_ (m a -> IO a
forall x. m x -> IO x
lower m a
ma) (m b -> IO b
forall x. m x -> IO x
lower m b
mb)
{-# INLINE concurrently_ #-}
mapConcurrently :: (Traversable t, Eff Conc m) => (a -> m b) -> t a -> m (t b)
mapConcurrently :: (a -> m b) -> t a -> m (t b)
mapConcurrently = (Concurrently m (t b) -> m (t b)
forall k (m :: k -> *) (a :: k). Concurrently m a -> m a
runConcurrently (Concurrently m (t b) -> m (t b))
-> (t a -> Concurrently m (t b)) -> t a -> m (t b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((t a -> Concurrently m (t b)) -> t a -> m (t b))
-> ((a -> Concurrently m b) -> t a -> Concurrently m (t b))
-> (a -> Concurrently m b)
-> t a
-> m (t b)
forall c b a. Coercible c b => (b -> c) -> (a -> b) -> a -> c
#. (a -> Concurrently m b) -> t a -> Concurrently m (t b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((a -> Concurrently m b) -> t a -> m (t b))
-> ((a -> m b) -> a -> Concurrently m b)
-> (a -> m b)
-> t a
-> m (t b)
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# (m b -> Concurrently m b
forall k (m :: k -> *) (a :: k). m a -> Concurrently m a
Concurrently (m b -> Concurrently m b) -> (a -> m b) -> a -> Concurrently m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.)
{-# INLINE mapConcurrently #-}
forConcurrently :: (Traversable t, Eff Conc m) => t a -> (a -> m b) -> m (t b)
forConcurrently :: t a -> (a -> m b) -> m (t b)
forConcurrently = ((a -> m b) -> t a -> m (t b)) -> t a -> (a -> m b) -> m (t b)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> m b) -> t a -> m (t b)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Eff Conc m) =>
(a -> m b) -> t a -> m (t b)
mapConcurrently
{-# INLINE forConcurrently #-}
mapConcurrently_ :: (Foldable t, Eff Conc m) => (a -> m b) -> t a -> m ()
mapConcurrently_ :: (a -> m b) -> t a -> m ()
mapConcurrently_ a -> m b
f = Concurrently m () -> m ()
forall k (m :: k -> *) (a :: k). Concurrently m a -> m a
runConcurrently (Concurrently m () -> m ())
-> (t a -> Concurrently m ()) -> t a -> m ()
forall c b a. Coercible c b => (b -> c) -> (a -> b) -> a -> c
#. (a -> Concurrently m ()) -> t a -> Concurrently m ()
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (m () -> Concurrently m ()
forall k (m :: k -> *) (a :: k). m a -> Concurrently m a
Concurrently (m () -> Concurrently m ())
-> (a -> m ()) -> a -> Concurrently m ()
forall c b a. Coercible c b => (b -> c) -> (a -> b) -> a -> c
#. m b -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m b -> m ()) -> (a -> m b) -> a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m b
f)
{-# INLINE mapConcurrently_ #-}
forConcurrently_ :: (Foldable t, Eff Conc m) => t a -> (a -> m b) -> m ()
forConcurrently_ :: t a -> (a -> m b) -> m ()
forConcurrently_ = ((a -> m b) -> t a -> m ()) -> t a -> (a -> m b) -> m ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> m b) -> t a -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Eff Conc m) =>
(a -> m b) -> t a -> m ()
mapConcurrently_
{-# INLINE forConcurrently_ #-}
replicateConcurrently :: Eff Conc m => Int -> m a -> m [a]
replicateConcurrently :: Int -> m a -> m [a]
replicateConcurrently Int
cnt = Concurrently m [a] -> m [a]
forall k (m :: k -> *) (a :: k). Concurrently m a -> m a
runConcurrently (Concurrently m [a] -> m [a])
-> (Concurrently m a -> Concurrently m [a])
-> Concurrently m a
-> m [a]
forall c b a. Coercible c b => (b -> c) -> (a -> b) -> a -> c
#. Int -> Concurrently m a -> Concurrently m [a]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
cnt (Concurrently m a -> m [a])
-> (m a -> Concurrently m a) -> m a -> m [a]
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# m a -> Concurrently m a
forall k (m :: k -> *) (a :: k). m a -> Concurrently m a
Concurrently
{-# INLINE replicateConcurrently #-}
replicateConcurrently_ :: Eff Conc m => Int -> m a -> m ()
replicateConcurrently_ :: Int -> m a -> m ()
replicateConcurrently_ Int
cnt = Concurrently m () -> m ()
forall k (m :: k -> *) (a :: k). Concurrently m a -> m a
runConcurrently (Concurrently m () -> m ())
-> (Concurrently m a -> Concurrently m ())
-> Concurrently m a
-> m ()
forall c b a. Coercible c b => (b -> c) -> (a -> b) -> a -> c
#. Int -> Concurrently m a -> Concurrently m ()
forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
cnt (Concurrently m a -> m ())
-> (m a -> Concurrently m a) -> m a -> m ()
forall b a c. Coercible b a => (b -> c) -> (a -> b) -> a -> c
.# m a -> Concurrently m a
forall k (m :: k -> *) (a :: k). m a -> Concurrently m a
Concurrently
{-# INLINE replicateConcurrently_ #-}
newtype Concurrently m a = Concurrently { Concurrently m a -> m a
runConcurrently :: m a }
deriving a -> Concurrently m b -> Concurrently m a
(a -> b) -> Concurrently m a -> Concurrently m b
(forall a b. (a -> b) -> Concurrently m a -> Concurrently m b)
-> (forall a b. a -> Concurrently m b -> Concurrently m a)
-> Functor (Concurrently m)
forall a b. a -> Concurrently m b -> Concurrently m a
forall a b. (a -> b) -> Concurrently m a -> Concurrently m b
forall (m :: * -> *) a b.
Functor m =>
a -> Concurrently m b -> Concurrently m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Concurrently m a -> Concurrently m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Concurrently m b -> Concurrently m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> Concurrently m b -> Concurrently m a
fmap :: (a -> b) -> Concurrently m a -> Concurrently m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Concurrently m a -> Concurrently m b
Functor
instance Eff Conc m => Applicative (Concurrently m) where
pure :: a -> Concurrently m a
pure = m a -> Concurrently m a
forall k (m :: k -> *) (a :: k). m a -> Concurrently m a
Concurrently (m a -> Concurrently m a) -> (a -> m a) -> a -> Concurrently m a
forall c b a. Coercible c b => (b -> c) -> (a -> b) -> a -> c
#. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
{-# INLINE pure #-}
Concurrently m (a -> b)
fs <*> :: Concurrently m (a -> b) -> Concurrently m a -> Concurrently m b
<*> Concurrently m a
as = m b -> Concurrently m b
forall k (m :: k -> *) (a :: k). m a -> Concurrently m a
Concurrently (m b -> Concurrently m b) -> m b -> Concurrently m b
forall a b. (a -> b) -> a -> b
$ ((forall x. m x -> IO x) -> IO b) -> m b
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO b) -> m b)
-> ((forall x. m x -> IO x) -> IO b) -> m b
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower ->
Concurrently b -> IO b
forall a. Concurrently a -> IO a
A.runConcurrently (IO (a -> b) -> Concurrently (a -> b)
forall a. IO a -> Concurrently a
A.Concurrently (m (a -> b) -> IO (a -> b)
forall x. m x -> IO x
lower m (a -> b)
fs) Concurrently (a -> b) -> Concurrently a -> Concurrently b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO a -> Concurrently a
forall a. IO a -> Concurrently a
A.Concurrently (m a -> IO a
forall x. m x -> IO x
lower m a
as))
{-# INLINE (<*>) #-}
instance Eff Conc m => Alternative (Concurrently m) where
empty :: Concurrently m a
empty = m a -> Concurrently m a
forall k (m :: k -> *) (a :: k). m a -> Concurrently m a
Concurrently (m a -> Concurrently m a) -> m a -> Concurrently m a
forall a b. (a -> b) -> a -> b
$ ((forall x. m x -> IO x) -> IO a) -> m a
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO a) -> m a)
-> ((forall x. m x -> IO x) -> IO a) -> m a
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
_ -> Concurrently a -> IO a
forall a. Concurrently a -> IO a
A.runConcurrently Concurrently a
forall (f :: * -> *) a. Alternative f => f a
empty
{-# INLINE empty #-}
Concurrently m a
as <|> :: Concurrently m a -> Concurrently m a -> Concurrently m a
<|> Concurrently m a
bs = m a -> Concurrently m a
forall k (m :: k -> *) (a :: k). m a -> Concurrently m a
Concurrently (m a -> Concurrently m a) -> m a -> Concurrently m a
forall a b. (a -> b) -> a -> b
$ ((forall x. m x -> IO x) -> IO a) -> m a
forall (m :: * -> *) a.
Eff Conc m =>
((forall x. m x -> IO x) -> IO a) -> m a
unliftConc (((forall x. m x -> IO x) -> IO a) -> m a)
-> ((forall x. m x -> IO x) -> IO a) -> m a
forall a b. (a -> b) -> a -> b
$ \forall x. m x -> IO x
lower ->
Concurrently a -> IO a
forall a. Concurrently a -> IO a
A.runConcurrently (IO a -> Concurrently a
forall a. IO a -> Concurrently a
A.Concurrently(m a -> IO a
forall x. m x -> IO x
lower m a
as) Concurrently a -> Concurrently a -> Concurrently a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> IO a -> Concurrently a
forall a. IO a -> Concurrently a
A.Concurrently (m a -> IO a
forall x. m x -> IO x
lower m a
bs))
{-# INLINE (<|>) #-}
instance (Eff Conc m, Semigroup a) => Semigroup (Concurrently m a) where
<> :: Concurrently m a -> Concurrently m a -> Concurrently m a
(<>) = (a -> a -> a)
-> Concurrently m a -> Concurrently m a -> Concurrently m a
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> a -> a
forall a. Semigroup a => a -> a -> a
(<>)
{-# INLINE (<>) #-}
instance (Eff Conc m, Monoid a) => Monoid (Concurrently m a) where
mempty :: Concurrently m a
mempty = a -> Concurrently m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
forall a. Monoid a => a
mempty
{-# INLINE mempty #-}