Safe Haskell | None |
---|---|
Language | Haskell2010 |
Control.Effects.Async
Synopsis
- data Async thread m = AsyncMethods {
- _async :: forall a. m a -> m (thread m a)
- _waitAsync :: forall a. thread m a -> m a
- _isAsyncDone :: forall a n. thread n a -> m Bool
- _cancelAsync :: forall a n. thread n a -> m ()
- class ThreadIdentifier thread where
- mapThread :: (m a -> n b) -> thread m a -> thread n b
- async :: MonadEffect (Async thread) m => m a -> m (thread m a)
- waitAsync :: MonadEffect (Async thread) m => thread m a -> m a
- isAsyncDone :: MonadEffect (Async thread) m => thread n a -> m Bool
- cancelAsync :: MonadEffect (Async thread) m => thread n a -> m ()
- newtype AsyncThread m a = AsyncThread (Async (m a))
- implementAsyncViaIO :: IO a -> IO a
- parallelMapM :: (MonadEffect (Async thread) m, Traversable t) => (a -> m b) -> t a -> m (t b)
- parallelMapM_ :: (MonadEffect (Async thread) m, Traversable t) => (a -> m b) -> t a -> m ()
Documentation
Constructors
AsyncMethods | |
Fields
|
Instances
ThreadIdentifier thread => Effect (Async thread) Source # | |
Defined in Control.Effects.Async Associated Types type CanLift (Async thread) t :: Constraint Source # type ExtraConstraint (Async thread) m :: Constraint Source # | |
MonadEffect (Async AsyncThread) IO Source # | The |
Defined in Control.Effects.Async | |
UniqueEffect Async IO AsyncThread Source # | |
Defined in Control.Effects.Async | |
UniqueEffect Async (RuntimeImplemented (Async thread) m) (thread :: (Type -> Type) -> Type -> Type) Source # | |
Defined in Control.Effects.Async | |
type CanLift (Async thread) t Source # | |
Defined in Control.Effects.Async | |
type ExtraConstraint (Async thread) m Source # | |
Defined in Control.Effects.Async |
class ThreadIdentifier thread where Source #
Instances
ThreadIdentifier AsyncThread Source # | |
Defined in Control.Effects.Async Methods mapThread :: (m a -> n b) -> AsyncThread m a -> AsyncThread n b Source # |
async :: MonadEffect (Async thread) m => m a -> m (thread m a) Source #
Fork a new thread to run the given computation. The monadic context is forked into the new thread.
For example, if we use state, the current state value will be visible in the forked computation.
Depending on how we ultimately implement the state, modifying it may or may not be visible
from the main thread. If we use implementStateViaStateT
then setting the state in the forked
thread will just modify the thread-local value. On the other hand, if we use
implementStateViaIORef
then both the main thread and the new thread will use the same reference
meaning they can interact through it.
waitAsync :: MonadEffect (Async thread) m => thread m a -> m a Source #
isAsyncDone :: MonadEffect (Async thread) m => thread n a -> m Bool Source #
Check if the asynchronous computation has finished (either normally, or with an exception)
cancelAsync :: MonadEffect (Async thread) m => thread n a -> m () Source #
Abort the asynchronous exception
newtype AsyncThread m a Source #
The type that represents the forked computation in the monad m
that eventually computes
a value of type a
. Depending on the monad, the computation may produce zero, one or even
multiple values of that type.
Constructors
AsyncThread (Async (m a)) |
Instances
implementAsyncViaIO :: IO a -> IO a Source #
This will discard the
constraint by forcing MonadEffect
Async
mm
to be IO
.
The functions doesn't actually do anything, the real implementation is given by the
instance which uses the MonadEffect
Async
IOasync
package.
parallelMapM :: (MonadEffect (Async thread) m, Traversable t) => (a -> m b) -> t a -> m (t b) Source #
Like mapM
but the supplied function is run in parallel asynchronously on all the elements.
The results will be in the same order as the inputs.
parallelMapM_ :: (MonadEffect (Async thread) m, Traversable t) => (a -> m b) -> t a -> m () Source #
Same as parallelMapM_
but discards the result.