Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module is designed to be imported qualified, e.g.
import qualified Control.Immortal as Immortal
- data Thread
- create :: MonadUnliftIO m => (Thread -> m ()) -> m Thread
- createWithLabel :: MonadUnliftIO m => String -> (Thread -> m ()) -> m Thread
- mortalize :: Thread -> IO ()
- immortalize :: Thread -> IO ()
- stop :: Thread -> IO ()
- wait :: Thread -> IO ()
- waitSTM :: Thread -> STM ()
- threadId :: Thread -> ThreadId
- onFinish :: MonadUnliftIO m => (Either SomeException () -> m ()) -> m () -> m ()
- onUnexpectedFinish :: MonadUnliftIO m => Thread -> (Either SomeException () -> m ()) -> m () -> m ()
Documentation
create :: MonadUnliftIO m => (Thread -> m ()) -> m Thread Source #
Spawn a new immortal thread running the given computation.
If the computation ever finishes (either normally or due to an exception), it will be restarted (in the same thread).
createWithLabel :: MonadUnliftIO m => String -> (Thread -> m ()) -> m Thread Source #
Like create
, but also apply the given label to the thread
(using labelThread
).
mortalize :: Thread -> IO () Source #
Make a thread mortal. Next time a mortal thread attempts to finish, nothing will prevent it from doing so.
Calling this on an already mortalized thread has no effect.
immortalize :: Thread -> IO () Source #
If a thread was mortalize
d, this will make it immortal again. However,
if it finished while being in the mortal state, it won't be resurrected.
Calling this on an immortal thread has no effect.
stop :: Thread -> IO () Source #
Stop (kill) an immortal thread.
This is equivalent to making it mortal, and then killing it with an exception.
Note that if the thread has installed its own exception handlers, it may not be killed immediately.
onFinish :: MonadUnliftIO m => (Either SomeException () -> m ()) -> m () -> m () Source #
Run a callback every time the action finishes. This can be used e.g. to log exceptions or attempts to exit when such attempts are not expected. Example usage:
Immortal.create $ \_ -> Immortal.onFinish print myAction
This is nothing more than a simple wrapper around try
.
onUnexpectedFinish :: MonadUnliftIO m => Thread -> (Either SomeException () -> m ()) -> m () -> m () Source #