unliftio-0.1.1.0: The MonadUnliftIO typeclass for unlifting monads to IO (batteries included)

Safe Haskell | Safe
Language | Haskell2010

UnliftIO.Async

Contents

- Asynchronous actions
  - Spawning
  - Spawning with automatic `cancel`ation
  - Querying `Async`s
  - STM operations
  - Waiting for multiple `Async`s
  - Waiting for multiple `Async`s in STM
  - Linking
- Convenient utilities

Description

Unlifted Control.Concurrent.Async.

Since: 0.1.0.0

Synopsis

- data Async a :: * -> *
- async :: MonadUnliftIO m => m a -> m (Async a)
- asyncBound :: MonadUnliftIO m => m a -> m (Async a)
- asyncOn :: MonadUnliftIO m => Int -> m a -> m (Async a)
- asyncWithUnmask :: MonadUnliftIO m => ((forall b. m b -> m b) -> m a) -> m (Async a)
- asyncOnWithUnmask :: MonadUnliftIO m => Int -> ((forall b. m b -> m b) -> m a) -> m (Async a)
- withAsync :: MonadUnliftIO m => m a -> (Async a -> m b) -> m b
- withAsyncBound :: MonadUnliftIO m => m a -> (Async a -> m b) -> m b
- withAsyncOn :: MonadUnliftIO m => Int -> m a -> (Async a -> m b) -> m b
- withAsyncWithUnmask :: MonadUnliftIO m => ((forall c. m c -> m c) -> m a) -> (Async a -> m b) -> m b
- withAsyncOnWithUnmask :: MonadUnliftIO m => Int -> ((forall c. m c -> m c) -> m a) -> (Async a -> m b) -> m b
- wait :: MonadIO m => Async a -> m a
- poll :: MonadIO m => Async a -> m (Maybe (Either SomeException a))
- waitCatch :: MonadIO m => Async a -> m (Either SomeException a)
- cancel :: MonadIO m => Async a -> m ()
- uninterruptibleCancel :: MonadIO m => Async a -> m ()
- cancelWith :: (Exception e, MonadIO m) => Async a -> e -> m ()
- asyncThreadId :: Async a -> ThreadId
- waitSTM :: Async a -> STM a
- pollSTM :: Async a -> STM (Maybe (Either SomeException a))
- waitCatchSTM :: Async a -> STM (Either SomeException a)
- waitAny :: MonadIO m => [Async a] -> m (Async a, a)
- waitAnyCatch :: MonadIO m => [Async a] -> m (Async a, Either SomeException a)
- waitAnyCancel :: MonadIO m => [Async a] -> m (Async a, a)
- waitAnyCatchCancel :: MonadIO m => [Async a] -> m (Async a, Either SomeException a)
- waitEither :: MonadIO m => Async a -> Async b -> m (Either a b)
- waitEitherCatch :: MonadIO m => Async a -> Async b -> m (Either (Either SomeException a) (Either SomeException b))
- waitEitherCancel :: MonadIO m => Async a -> Async b -> m (Either a b)
- waitEitherCatchCancel :: MonadIO m => Async a -> Async b -> m (Either (Either SomeException a) (Either SomeException b))
- waitEither_ :: MonadIO m => Async a -> Async b -> m ()
- waitBoth :: MonadIO m => Async a -> Async b -> m (a, b)
- waitAnySTM :: [Async a] -> STM (Async a, a)
- waitAnyCatchSTM :: [Async a] -> STM (Async a, Either SomeException a)
- waitEitherSTM :: Async a -> Async b -> STM (Either a b)
- waitEitherCatchSTM :: Async a -> Async b -> STM (Either (Either SomeException a) (Either SomeException b))
- waitEitherSTM_ :: Async a -> Async b -> STM ()
- waitBothSTM :: Async a -> Async b -> STM (a, b)
- link :: MonadIO m => Async a -> m ()
- link2 :: MonadIO m => Async a -> Async b -> m ()
- race :: MonadUnliftIO m => m a -> m b -> m (Either a b)
- race_ :: MonadUnliftIO m => m a -> m b -> m ()
- concurrently :: MonadUnliftIO m => m a -> m b -> m (a, b)
- concurrently_ :: MonadUnliftIO m => m a -> m b -> m ()
- mapConcurrently :: MonadUnliftIO m => Traversable t => (a -> m b) -> t a -> m (t b)
- forConcurrently :: MonadUnliftIO m => Traversable t => t a -> (a -> m b) -> m (t b)
- mapConcurrently_ :: MonadUnliftIO m => Foldable f => (a -> m b) -> f a -> m ()
- forConcurrently_ :: MonadUnliftIO m => Foldable f => f a -> (a -> m b) -> m ()
- replicateConcurrently :: MonadUnliftIO m => Int -> m a -> m [a]
- replicateConcurrently_ :: MonadUnliftIO m => Int -> m a -> m ()
- newtype Concurrently m a = Concurrently {
  - runConcurrently :: m a
  }

# Asynchronous actions

data Async a :: * -> * #

An asynchronous action spawned by `async` or `withAsync`. Asynchronous actions are executed in a separate thread, and operations are provided for waiting for asynchronous actions to complete and obtaining their results (see e.g. `wait`).

Instances

Functor Async |
Methods fmap :: (a -> b) -> Async a -> Async b # (<$) :: a -> Async b -> Async a #
Eq (Async a) |
Methods (==) :: Async a -> Async a -> Bool # (/=) :: Async a -> Async a -> Bool #
Ord (Async a) |
Methods compare :: Async a -> Async a -> Ordering # (<) :: Async a -> Async a -> Bool # (<=) :: Async a -> Async a -> Bool # (>) :: Async a -> Async a -> Bool # (>=) :: Async a -> Async a -> Bool # max :: Async a -> Async a -> Async a # min :: Async a -> Async a -> Async a #

## Spawning

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

Unlifted `async`.

Since: 0.1.0.0

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

Unlifted `asyncBound`.

Since: 0.1.0.0

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

Unlifted `asyncOn`.

Since: 0.1.0.0

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

Unlifted `asyncWithUnmask`.

Since: 0.1.0.0

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

Unlifted `asyncOnWithUnmask`.

Since: 0.1.0.0

## Spawning with automatic `cancel`ation

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

Unlifted `withAsync`.

Since: 0.1.0.0

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

Unlifted `withAsyncBound`.

Since: 0.1.0.0

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

Unlifted `withAsyncOn`.

Since: 0.1.0.0

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

Unlifted `withAsyncWithUnmask`.

Since: 0.1.0.0

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

Unlifted `withAsyncOnWithMask`.

Since: 0.1.0.0

## Querying `Async`s

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

Lifted `wait`.

Since: 0.1.0.0

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

Lifted `poll`.

Since: 0.1.0.0

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

Lifted `waitCatch`.

Since: 0.1.0.0

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

Lifted `cancel`.

Since: 0.1.0.0

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

Lifted `uninterruptibleCancel`.

Since: 0.1.0.0

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

Lifted `cancelWith`. Additionally uses `toAsyncException` to ensure async exception safety.

Since: 0.1.0.0

asyncThreadId :: Async a -> ThreadId #

Returns the `ThreadId` of the thread running the given `Async`.

## STM operations

waitSTM :: Async a -> STM a #

A version of `wait` that can be used inside an STM transaction.

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

A version of `poll` that can be used inside an STM transaction.

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

A version of `waitCatch` that can be used inside an STM transaction.

## Waiting for multiple `Async`s

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

Lifted `waitAny`.

Since: 0.1.0.0

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

Lifted `waitAnyCatch`.

Since: 0.1.0.0

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

Lifted `waitAnyCancel`.

Since: 0.1.0.0

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

Lifted `waitAnyCatchCancel`.

Since: 0.1.0.0

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

Lifted `waitEither`.

Since: 0.1.0.0

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

Lifted `waitEitherCatch`.

Since: 0.1.0.0

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

Lifted `waitEitherCancel`.

Since: 0.1.0.0

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

Lifted `waitEitherCatchCancel`.

Since: 0.1.0.0

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

Lifted `waitEither_`.

Since: 0.1.0.0

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

Lifted `waitBoth`.

Since: 0.1.0.0

## Waiting for multiple `Async`s in STM

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

A version of `waitAny` that can be used inside an STM transaction.

Since: 2.1.0

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

A version of `waitAnyCatch` that can be used inside an STM transaction.

Since: 2.1.0

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

A version of `waitEither` that can be used inside an STM transaction.

Since: 2.1.0

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

A version of `waitEitherCatch` that can be used inside an STM transaction.

Since: 2.1.0

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

A version of `waitEither_` that can be used inside an STM transaction.

Since: 2.1.0

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

A version of `waitBoth` that can be used inside an STM transaction.

Since: 2.1.0

## Linking

link :: MonadIO m => Async a -> m () Source #

Lifted `link`.

Since: 0.1.0.0

link2 :: MonadIO m => Async a -> Async b -> m () Source #

Lifted `link2`.

Since: 0.1.0.0

# Convenient utilities

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

Unlifted `race`.

Since: 0.1.0.0

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

Unlifted `race_`.

Since: 0.1.0.0

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

Unlifted `concurrently`.

Since: 0.1.0.0

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

Unlifted `concurrently_`.

Since: 0.1.0.0

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

Unlifted `mapConcurrently`.

Since: 0.1.0.0

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

Unlifted `forConcurrently`.

Since: 0.1.0.0

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

Unlifted `mapConcurrently_`.

Since: 0.1.0.0

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

Unlifted `forConcurrently_`.

Since: 0.1.0.0

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

Unlifted `replicateConcurrently`.

Since: 0.1.0.0

replicateConcurrently_ :: MonadUnliftIO m => Int -> m a -> m () Source #

Unlifted `replicateConcurrently_`.

Since: 0.1.0.0

newtype Concurrently m a Source #

Unlifted `Concurrently`.

Since: 0.1.0.0

Constructors

Concurrently |

Fields

- runConcurrently :: m a

Instances

Monad m => Functor (Concurrently m) Source # | Since: 0.1.0.0
Methods fmap :: (a -> b) -> Concurrently m a -> Concurrently m b # (<$) :: a -> Concurrently m b -> Concurrently m a #
MonadUnliftIO m => Applicative (Concurrently m) Source # | Since: 0.1.0.0
Methods pure :: a -> Concurrently m a # (<*>) :: Concurrently m (a -> b) -> Concurrently m a -> Concurrently m b # (*>) :: Concurrently m a -> Concurrently m b -> Concurrently m b # (<*) :: Concurrently m a -> Concurrently m b -> Concurrently m a #
MonadUnliftIO m => Alternative (Concurrently m) Source # | Since: 0.1.0.0
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] #
(MonadUnliftIO m, Semigroup a) => Semigroup (Concurrently m a) Source # | Only defined by `async` for `base >= 4.9`. Since: 0.1.0.0
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 #
(Semigroup a, Monoid a, MonadUnliftIO m) => Monoid (Concurrently m a) Source # | Since: 0.1.0.0
Methods mempty :: Concurrently m a # mappend :: Concurrently m a -> Concurrently m a -> Concurrently m a # mconcat :: [Concurrently m a] -> Concurrently m a #