| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
ConIO.Core
Synopsis
- data ConIO a
- runConIO :: MonadIO m => ConIO a -> m a
- runConIOCancel :: MonadIO m => ConIO a -> m a
- data Task a = Task {}
- launch :: IO a -> ConIO (Task a)
- wait :: MonadSTM m => Task a -> m a
- cancel :: MonadIO m => Task a -> m ()
- cancelAll :: ConIO ()
- linkTasks :: Task a -> Task b -> Task b
- data ConScope (s :: k)
- withConScope :: (forall (s :: k). ConScope s -> IO a) -> ConIO a
- useConScope :: forall {k} (s :: k) a. ConScope s -> ConIO a -> IO a
- data UnsafeConScope
- toUnsafeConScope :: forall {k} (s :: k). ConScope s -> UnsafeConScope
- fromUnsafeConScope :: UnsafeConScope -> (forall (s :: k). ConScope s -> a) -> a
- data ConIOException
- data ConIOKillThread = ConIOKillThread
Concurrent IO
ConIO stands for concurrent IO. ConIO works like normal IO,
but you can also fork off threads without worry.
Threads launched within ConIO will never outlive the ConIO scope.
Before ConIO ends, it will wait for all threads to finish or cancel them.
Additionally, exceptions between parent and children are propagated per default,
completely shutting down all processes when an exception happens anywhere.
You do not have to worry about:
- Zombie processes, since a thread can never outlive its parent scope.
- Dead processes, since exceptions will propagate to the parent thread.
runConIOCancel :: MonadIO m => ConIO a -> m a Source #
Opens up a concurrent scope by running 'ConIO. Cancels all tasks before returning.
Tasks
A Task represents a thread which is producing some a. You can wait for tasks or cancel them.
The internals of Task are exposed if you need them. However, this ought not to be necessary.
cancel :: MonadIO m => Task a -> m () Source #
Cancel a Task, killing all threads which are part of producing the a value.
cancel returns immediately and does not wait for the canceled threads to die.
If you want to wait for threads to die, you need to start them in a separate scope.
If you cancel a Task which comprises other ones (e.g. by using <*>), it will cancel the contained tasks.
linkTasks :: Task a -> Task b -> Task b Source #
Create a new task which produces the same result as task b.
When you cancel the new task, you cancel both task a and task b.
Manage scopes
withConScope :: (forall (s :: k). ConScope s -> IO a) -> ConIO a Source #
Get the ConIO scope and use it in an internal computation.
The `forall s.` prevents incorrect usage of the scope.
data UnsafeConScope Source #
An UnsafeConScope has no forall quantifier,
making it possible for scopes to escape their originating ConIO.
Use this only if you know what you are doing.
toUnsafeConScope :: forall {k} (s :: k). ConScope s -> UnsafeConScope Source #
fromUnsafeConScope :: UnsafeConScope -> (forall (s :: k). ConScope s -> a) -> a Source #
Exceptions
data ConIOException Source #
ConIOException is used for all exceptions related to threads created by launch.
Constructors
| ConIODisabled | Happens when you try to |
| ConIOTaskException SomeException | Happens when a child thread throws an exception |
Instances
| Exception ConIOException Source # | |
Defined in ConIO.Core Methods toException :: ConIOException -> SomeException # fromException :: SomeException -> Maybe ConIOException # displayException :: ConIOException -> String # backtraceDesired :: ConIOException -> Bool # | |
| Show ConIOException Source # | |
Defined in ConIO.Core Methods showsPrec :: Int -> ConIOException -> ShowS # show :: ConIOException -> String # showList :: [ConIOException] -> ShowS # | |
data ConIOKillThread Source #
The ConIOKillThread exception is used internally to kill threads without bringing down the whole ConIO scope.
Do not catch this exception, unless you know what you are doing.
Keep in mind to rethrow AsyncException if you catch SomeException!
A normal SIGKILL triggered by the external system will shutdown the whole ConIO scope.
Constructors
| ConIOKillThread |
Instances
| Exception ConIOKillThread Source # | |
Defined in ConIO.Core Methods toException :: ConIOKillThread -> SomeException # fromException :: SomeException -> Maybe ConIOKillThread # displayException :: ConIOKillThread -> String # backtraceDesired :: ConIOKillThread -> Bool # | |
| Show ConIOKillThread Source # | |
Defined in ConIO.Core Methods showsPrec :: Int -> ConIOKillThread -> ShowS # show :: ConIOKillThread -> String # showList :: [ConIOKillThread] -> ShowS # | |