Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides abstractions for parallel job processing.
- data InterruptType
- = Plain
- | Force
- | WithTimeout !Microsecond !(IO ())
- newtype JobCurator = JobCurator {
- getJobCurator :: TVar JobCuratorState
- jcCounter :: Lens' JobCuratorState JobId
- jcIsClosed :: Lens' JobCuratorState Bool
- jcJobs :: Lens' JobCuratorState (HashMap JobId JobInterrupter)
- addManagerAsJob :: (MonadIO m, MonadTimed m, MonadBaseControl IO m) => JobCurator -> InterruptType -> JobCurator -> m ()
- addSafeThreadJob :: (MonadIO m, MonadMask m, MonadTimed m) => JobCurator -> m () -> m ()
- addThreadJob :: (CanLog m, MonadIO m, MonadMask m, MonadTimed m, MonadBaseControl IO m) => JobCurator -> m () -> m ()
- interruptAllJobs :: MonadIO m => JobCurator -> InterruptType -> m ()
- isInterrupted :: MonadIO m => JobCurator -> m Bool
- mkJobCurator :: MonadIO m => m JobCurator
- stopAllJobs :: MonadIO m => JobCurator -> m ()
- unlessInterrupted :: MonadIO m => JobCurator -> m () -> m ()
Job data types
data InterruptType Source #
Defines way to interrupt all jobs in curator.
Plain | Just interrupt all jobs |
Force | Interrupt all jobs, and treat them all as completed |
WithTimeout !Microsecond !(IO ()) | Interrupt all jobs in |
newtype JobCurator Source #
Keeps set of jobs. Allows to stop jobs and wait till all of them finish.
JobCurator | |
|
JobsState
lenses
jcIsClosed :: Lens' JobCuratorState Bool Source #
Manager utilities
addManagerAsJob :: (MonadIO m, MonadTimed m, MonadBaseControl IO m) => JobCurator -> InterruptType -> JobCurator -> m () Source #
Add second manager as a job to first manager.
addSafeThreadJob :: (MonadIO m, MonadMask m, MonadTimed m) => JobCurator -> m () -> m () Source #
Adds job executing in another thread, interrupting does nothing. Usefull then work stops itself on interrupt, and we just need to wait till it fully stops.
addThreadJob :: (CanLog m, MonadIO m, MonadMask m, MonadTimed m, MonadBaseControl IO m) => JobCurator -> m () -> m () Source #
Adds job executing in another thread, where interrupting kills the thread.
interruptAllJobs :: MonadIO m => JobCurator -> InterruptType -> m () Source #
Invokes JobInterrupter
s for all incompleted jobs.
Has no effect on second call.
isInterrupted :: MonadIO m => JobCurator -> m Bool Source #
mkJobCurator :: MonadIO m => m JobCurator Source #
stopAllJobs :: MonadIO m => JobCurator -> m () Source #
Interrupts and then awaits for all jobs to complete.
unlessInterrupted :: MonadIO m => JobCurator -> m () -> m () Source #