| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Control.Effects.Async
- data Async
- newtype AsyncThread m a = AsyncThread (Async (m a))
- async :: MonadEffect Async m => m a -> m (AsyncThread m a)
- waitAsync :: MonadEffect Async m => AsyncThread m a -> m a
- implementAsyncViaIO :: IO a -> IO a
Documentation
The name of the effect
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
| Functor m => Functor (AsyncThread m) Source # | |
| Eq (AsyncThread m a) Source # | |
| Ord (AsyncThread m a) Source # | |
async :: MonadEffect Async m => m a -> m (AsyncThread 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 int he 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 m => AsyncThread m a -> m a Source #
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.