io-sim-classes-0.2.0.0: Type classes for concurrency with STM, ST and timing
Safe HaskellNone
LanguageHaskell2010

Control.Monad.Class.MonadAsync

Synopsis

Documentation

class (MonadSTM m, MonadThread m, MonadAsyncSTM (Async m) (STM m)) => MonadAsync m where Source #

Minimal complete definition

async, asyncThreadId, cancel, cancelWith, asyncWithUnmask

Associated Types

type Async m :: Type -> Type Source #

An asynchronous action

Methods

async :: m a -> m (Async m a) Source #

asyncThreadId :: Proxy m -> Async m a -> ThreadId m Source #

withAsync :: m a -> (Async m a -> m b) -> m b Source #

default withAsync :: MonadMask m => m a -> (Async m a -> m b) -> m b Source #

wait :: Async m a -> m a Source #

poll :: Async m a -> m (Maybe (Either SomeException a)) Source #

waitCatch :: Async m a -> m (Either SomeException a) Source #

cancel :: Async m a -> m () Source #

cancelWith :: Exception e => Async m a -> e -> m () Source #

uninterruptibleCancel :: Async m a -> m () Source #

default uninterruptibleCancel :: MonadMask m => Async m a -> m () Source #

waitAny :: [Async m a] -> m (Async m a, a) Source #

waitAnyCatch :: [Async m a] -> m (Async m a, Either SomeException a) Source #

waitAnyCancel :: [Async m a] -> m (Async m a, a) Source #

default waitAnyCancel :: MonadThrow m => [Async m a] -> m (Async m a, a) Source #

waitAnyCatchCancel :: [Async m a] -> m (Async m a, Either SomeException a) Source #

default waitAnyCatchCancel :: MonadThrow m => [Async m a] -> m (Async m a, Either SomeException a) Source #

waitEither :: Async m a -> Async m b -> m (Either a b) Source #

waitEitherCatch :: Async m a -> Async m b -> m (Either (Either SomeException a) (Either SomeException b)) Source #

Note, IO-based implementations should override the default implementation. See the async package implementation and comments. http://hackage.haskell.org/package/async-2.2.1/docs/src/Control.Concurrent.Async.html#waitEitherCatch

waitEitherCancel :: Async m a -> Async m b -> m (Either a b) Source #

default waitEitherCancel :: MonadThrow m => Async m a -> Async m b -> m (Either a b) Source #

waitEitherCatchCancel :: Async m a -> Async m b -> m (Either (Either SomeException a) (Either SomeException b)) Source #

waitEither_ :: Async m a -> Async m b -> m () Source #

waitBoth :: Async m a -> Async m b -> m (a, b) Source #

race :: m a -> m b -> m (Either a b) Source #

race_ :: m a -> m b -> m () Source #

concurrently :: m a -> m b -> m (a, b) Source #

concurrently_ :: m a -> m b -> m () Source #

asyncWithUnmask :: ((forall b. m b -> m b) -> m a) -> m (Async m a) Source #

Instances

Instances details
MonadAsync IO Source # 
Instance details

Defined in Control.Monad.Class.MonadAsync

Associated Types

type Async IO :: Type -> Type Source #

Methods

async :: IO a -> IO (Async IO a) Source #

asyncThreadId :: Proxy IO -> Async IO a -> ThreadId IO Source #

withAsync :: IO a -> (Async IO a -> IO b) -> IO b Source #

wait :: Async IO a -> IO a Source #

poll :: Async IO a -> IO (Maybe (Either SomeException a)) Source #

waitCatch :: Async IO a -> IO (Either SomeException a) Source #

cancel :: Async IO a -> IO () Source #

cancelWith :: Exception e => Async IO a -> e -> IO () Source #

uninterruptibleCancel :: Async IO a -> IO () Source #

waitAny :: [Async IO a] -> IO (Async IO a, a) Source #

waitAnyCatch :: [Async IO a] -> IO (Async IO a, Either SomeException a) Source #

waitAnyCancel :: [Async IO a] -> IO (Async IO a, a) Source #

waitAnyCatchCancel :: [Async IO a] -> IO (Async IO a, Either SomeException a) Source #

waitEither :: Async IO a -> Async IO b -> IO (Either a b) Source #

waitEitherCatch :: Async IO a -> Async IO b -> IO (Either (Either SomeException a) (Either SomeException b)) Source #

waitEitherCancel :: Async IO a -> Async IO b -> IO (Either a b) Source #

waitEitherCatchCancel :: Async IO a -> Async IO b -> IO (Either (Either SomeException a) (Either SomeException b)) Source #

waitEither_ :: Async IO a -> Async IO b -> IO () Source #

waitBoth :: Async IO a -> Async IO b -> IO (a, b) Source #

race :: IO a -> IO b -> IO (Either a b) Source #

race_ :: IO a -> IO b -> IO () Source #

concurrently :: IO a -> IO b -> IO (a, b) Source #

concurrently_ :: IO a -> IO b -> IO () Source #

asyncWithUnmask :: ((forall b. IO b -> IO b) -> IO a) -> IO (Async IO a) Source #

MonadAsync m => MonadAsync (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Class.MonadAsync

Associated Types

type Async (ReaderT r m) :: Type -> Type Source #

Methods

async :: ReaderT r m a -> ReaderT r m (Async (ReaderT r m) a) Source #

asyncThreadId :: Proxy (ReaderT r m) -> Async (ReaderT r m) a -> ThreadId (ReaderT r m) Source #

withAsync :: ReaderT r m a -> (Async (ReaderT r m) a -> ReaderT r m b) -> ReaderT r m b Source #

wait :: Async (ReaderT r m) a -> ReaderT r m a Source #

poll :: Async (ReaderT r m) a -> ReaderT r m (Maybe (Either SomeException a)) Source #

waitCatch :: Async (ReaderT r m) a -> ReaderT r m (Either SomeException a) Source #

cancel :: Async (ReaderT r m) a -> ReaderT r m () Source #

cancelWith :: Exception e => Async (ReaderT r m) a -> e -> ReaderT r m () Source #

uninterruptibleCancel :: Async (ReaderT r m) a -> ReaderT r m () Source #

waitAny :: [Async (ReaderT r m) a] -> ReaderT r m (Async (ReaderT r m) a, a) Source #

waitAnyCatch :: [Async (ReaderT r m) a] -> ReaderT r m (Async (ReaderT r m) a, Either SomeException a) Source #

waitAnyCancel :: [Async (ReaderT r m) a] -> ReaderT r m (Async (ReaderT r m) a, a) Source #

waitAnyCatchCancel :: [Async (ReaderT r m) a] -> ReaderT r m (Async (ReaderT r m) a, Either SomeException a) Source #

waitEither :: Async (ReaderT r m) a -> Async (ReaderT r m) b -> ReaderT r m (Either a b) Source #

waitEitherCatch :: Async (ReaderT r m) a -> Async (ReaderT r m) b -> ReaderT r m (Either (Either SomeException a) (Either SomeException b)) Source #

waitEitherCancel :: Async (ReaderT r m) a -> Async (ReaderT r m) b -> ReaderT r m (Either a b) Source #

waitEitherCatchCancel :: Async (ReaderT r m) a -> Async (ReaderT r m) b -> ReaderT r m (Either (Either SomeException a) (Either SomeException b)) Source #

waitEither_ :: Async (ReaderT r m) a -> Async (ReaderT r m) b -> ReaderT r m () Source #

waitBoth :: Async (ReaderT r m) a -> Async (ReaderT r m) b -> ReaderT r m (a, b) Source #

race :: ReaderT r m a -> ReaderT r m b -> ReaderT r m (Either a b) Source #

race_ :: ReaderT r m a -> ReaderT r m b -> ReaderT r m () Source #

concurrently :: ReaderT r m a -> ReaderT r m b -> ReaderT r m (a, b) Source #

concurrently_ :: ReaderT r m a -> ReaderT r m b -> ReaderT r m () Source #

asyncWithUnmask :: ((forall b. ReaderT r m b -> ReaderT r m b) -> ReaderT r m a) -> ReaderT r m (Async (ReaderT r m) a) Source #

class (Functor async, MonadSTMTx stm) => MonadAsyncSTM async stm where Source #

Minimal complete definition

waitCatchSTM, pollSTM

Methods

waitSTM :: async a -> stm a Source #

default waitSTM :: MonadThrow stm => async a -> stm a Source #

pollSTM :: async a -> stm (Maybe (Either SomeException a)) Source #

waitCatchSTM :: async a -> stm (Either SomeException a) Source #

waitAnySTM :: [async a] -> stm (async a, a) Source #

default waitAnySTM :: MonadThrow stm => [async a] -> stm (async a, a) Source #

waitAnyCatchSTM :: [async a] -> stm (async a, Either SomeException a) Source #

waitEitherSTM :: async a -> async b -> stm (Either a b) Source #

default waitEitherSTM :: MonadThrow stm => async a -> async b -> stm (Either a b) Source #

waitEitherSTM_ :: async a -> async b -> stm () Source #

default waitEitherSTM_ :: MonadThrow stm => async a -> async b -> stm () Source #

waitEitherCatchSTM :: async a -> async b -> stm (Either (Either SomeException a) (Either SomeException b)) Source #

waitBothSTM :: async a -> async b -> stm (a, b) Source #

default waitBothSTM :: MonadThrow stm => async a -> async b -> stm (a, b) Source #

data ExceptionInLinkedThread Source #

Exception from child thread re-raised in parent thread

We record the thread ID of the child thread as a String. This avoids an m parameter in the type, which is important: ExceptionInLinkedThread must be an instance of Exception, requiring it to be Typeable; if m appeared in the type, we would require m to be Typeable, which does not work with with the simulator, as it would require a Typeable constraint on the s parameter of IOSim.

link :: (MonadAsync m, MonadFork m, MonadMask m) => Async m a -> m () Source #

linkTo :: (MonadAsync m, MonadFork m, MonadMask m) => ThreadId m -> Async m a -> m () Source #

Generalizion of link that links an async to an arbitrary thread.

linkOnly :: forall m a. (MonadAsync m, MonadFork m, MonadMask m) => (SomeException -> Bool) -> Async m a -> m () Source #

linkToOnly :: forall m a. (MonadAsync m, MonadFork m, MonadMask m) => ThreadId m -> (SomeException -> Bool) -> Async m a -> m () Source #

mapConcurrently :: (Traversable t, MonadAsync m) => (a -> m b) -> t a -> m (t b) Source #

forConcurrently :: (Traversable t, MonadAsync m) => t a -> (a -> m b) -> m (t b) Source #

mapConcurrently_ :: (Foldable f, MonadAsync m) => (a -> m b) -> f a -> m () Source #

forConcurrently_ :: (Foldable f, MonadAsync m) => f a -> (a -> m b) -> m () Source #

replicateConcurrently :: MonadAsync m => Int -> m a -> m [a] Source #

newtype Concurrently m a Source #

Similar to Concurrently but which works for any MonadAsync instance.

Constructors

Concurrently 

Fields

Instances

Instances details
Functor m => Functor (Concurrently m) Source # 
Instance details

Defined in Control.Monad.Class.MonadAsync

Methods

fmap :: (a -> b) -> Concurrently m a -> Concurrently m b #

(<$) :: a -> Concurrently m b -> Concurrently m a #

(Applicative m, MonadAsync m) => Applicative (Concurrently m) Source # 
Instance details

Defined in Control.Monad.Class.MonadAsync

Methods

pure :: a -> Concurrently m a #

(<*>) :: Concurrently m (a -> b) -> Concurrently m a -> Concurrently m b #

liftA2 :: (a -> b -> c) -> Concurrently m a -> Concurrently m b -> Concurrently m c #

(*>) :: Concurrently m a -> Concurrently m b -> Concurrently m b #

(<*) :: Concurrently m a -> Concurrently m b -> Concurrently m a #

(Alternative m, MonadAsync m, MonadTimer m) => Alternative (Concurrently m) Source # 
Instance details

Defined in Control.Monad.Class.MonadAsync

Methods

empty :: Concurrently m a #

(<|>) :: Concurrently m a -> Concurrently m a -> Concurrently m a #

some :: Concurrently m a -> Concurrently m [a] #

many :: Concurrently m a -> Concurrently m [a] #

(Semigroup a, MonadAsync m) => Semigroup (Concurrently m a) Source # 
Instance details

Defined in Control.Monad.Class.MonadAsync

Methods

(<>) :: Concurrently m a -> Concurrently m a -> Concurrently m a #

sconcat :: NonEmpty (Concurrently m a) -> Concurrently m a #

stimes :: Integral b => b -> Concurrently m a -> Concurrently m a #

(Monoid a, MonadAsync m) => Monoid (Concurrently m a) Source # 
Instance details

Defined in Control.Monad.Class.MonadAsync