io-classes-1.0.0.0: Type classes for concurrency with STM, ST and timing
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Monad.Class.MonadAsync

Synopsis

Documentation

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

Associated Types

type Async m = (async :: Type -> Type) | async -> m Source #

An asynchronous action

See Async.

Methods

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

See async.

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

asyncOn :: Int -> m a -> m (Async m a) Source #

See asyncOn.

asyncThreadId :: 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 #

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

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

withAsyncOn :: Int -> m a -> (Async m a -> m b) -> m b Source #

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

waitSTM :: Async m a -> STM m a Source #

See waitSTM.

default waitSTM :: MonadThrow (STM m) => Async m a -> STM m a Source #

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

See pollSTM.

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

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

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

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

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

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

waitEitherSTM_ :: Async m a -> Async m b -> STM m () Source #

default waitEitherSTM_ :: MonadThrow (STM m) => Async m a -> Async m b -> STM m () Source #

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

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

default waitBothSTM :: MonadThrow (STM m) => Async m a -> Async m b -> STM m (a, b) Source #

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

See wait.

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

See poll.

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

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

See cancel.

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 #

See waitAny.

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

See 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 #

See race.

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

See race_.

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 #

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

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

default withAsyncWithUnmask :: MonadMask m => ((forall c. m c -> m c) -> m a) -> (Async m a -> m b) -> m b Source #

withAsyncOnWithUnmask :: Int -> ((forall c. m c -> m c) -> m a) -> (Async m a -> m b) -> m b Source #

default withAsyncOnWithUnmask :: MonadMask m => Int -> ((forall c. m c -> m c) -> m a) -> (Async m a -> m b) -> m b Source #

compareAsyncs :: Async m a -> Async m b -> Ordering Source #

default compareAsyncs :: Ord (ThreadId m) => Async m a -> Async m b -> Ordering Source #

Instances

Instances details
MonadAsync IO Source # 
Instance details

Defined in Control.Monad.Class.MonadAsync

Associated Types

type Async IO = (async :: Type -> Type) Source #

Methods

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

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

asyncOn :: Int -> IO a -> IO (Async IO a) Source #

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

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

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

withAsyncOn :: Int -> IO a -> (Async IO a -> IO b) -> IO b Source #

waitSTM :: Async IO a -> STM IO a Source #

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

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

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

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

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

waitEitherSTM_ :: Async IO a -> Async IO b -> STM IO () Source #

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

waitBothSTM :: Async IO a -> Async IO b -> STM IO (a, 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 #

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

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

withAsyncOnWithUnmask :: Int -> ((forall c. IO c -> IO c) -> IO a) -> (Async IO a -> IO b) -> IO b Source #

compareAsyncs :: Async IO a -> Async IO b -> Ordering Source #

(MonadAsync m, MonadCatch (STM m), MonadFork m, MonadMask m) => MonadAsync (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Class.MonadAsync

Associated Types

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

Methods

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

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

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

asyncThreadId :: 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 #

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

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

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

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

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

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

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

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

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

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

waitBothSTM :: Async (ReaderT r m) a -> Async (ReaderT r m) b -> STM (ReaderT r m) (a, 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 #

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

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

withAsyncOnWithUnmask :: Int -> ((forall c. ReaderT r m c -> ReaderT r m c) -> ReaderT r m a) -> (Async (ReaderT r m) a -> ReaderT r m b) -> ReaderT r m b Source #

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

data AsyncCancelled #

The exception thrown by cancel to terminate a thread.

Constructors

AsyncCancelled 

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 #

Like link.

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

Like linkOnly.

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

Like link2.

link2Only :: (MonadAsync m, MonadFork m, MonadMask m) => (SomeException -> Bool) -> Async m a -> Async m b -> m () Source #

Like link2Only.

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 #

newtype Concurrently m a Source #

Similar to Concurrently but which works for any MonadAsync instance.

Constructors

Concurrently 

Fields

Instances

Instances details
(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] #

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 #

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 #

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

Defined in Control.Monad.Class.MonadAsync

(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 #