Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
This module provides the ability to create reapers: dedicated cleanup threads. These threads will automatically spawn and die based on the presence of a workload to process on.
- data ReaperSettings workload item
- defaultReaperSettings :: ReaperSettings [item] item
- reaperAction :: ReaperSettings workload item -> workload -> IO (workload -> workload)
- reaperDelay :: ReaperSettings workload item -> Int
- reaperCons :: ReaperSettings workload item -> item -> workload -> workload
- reaperNull :: ReaperSettings workload item -> workload -> Bool
- reaperEmpty :: ReaperSettings workload item -> workload
- data Reaper workload item = Reaper {
- reaperAdd :: item -> IO ()
- reaperRead :: IO workload
- reaperStop :: IO workload
- reaperKill :: IO ()
- mkReaper :: ReaperSettings workload item -> IO (Reaper workload item)
- mkListAction :: (item -> IO (Maybe item')) -> [item] -> IO ([item'] -> [item'])
Settings
data ReaperSettings workload item Source
Settings for creating a reaper. This type has two parameters:
workload
gives the entire workload, whereas item
gives an
individual piece of the queue. A common approach is to have workload
be a list of item
s. This is encouraged by defaultReaperSettings
and
mkListAction
.
Since 0.1.1
defaultReaperSettings :: ReaperSettings [item] item Source
Default ReaperSettings
value, biased towards having a list of work
items.
Since 0.1.1
Accessors
reaperAction :: ReaperSettings workload item -> workload -> IO (workload -> workload) Source
The action to perform on a workload. The result of this is a
"workload modifying" function. In the common case of using lists,
the result should be a difference list that prepends the remaining
workload to the temporary workload. For help with setting up such
an action, see mkListAction
.
Default: do nothing with the workload, and then prepend it to the temporary workload. This is incredibly useless; you should definitely override this default.
Since 0.1.1
reaperDelay :: ReaperSettings workload item -> Int Source
reaperCons :: ReaperSettings workload item -> item -> workload -> workload Source
Add an item onto a workload.
Default: list consing.
Since 0.1.1
reaperNull :: ReaperSettings workload item -> workload -> Bool Source
Check if a workload is empty, in which case the worker thread will shut down.
Default: null
.
Since 0.1.1
reaperEmpty :: ReaperSettings workload item -> workload Source
An empty workload.
Default: empty list.
Since 0.1.1
Type
data Reaper workload item Source
A data structure to hold reaper APIs.
Reaper | |
|
Creation
mkReaper :: ReaperSettings workload item -> IO (Reaper workload item) Source
Create a reaper addition function. This funciton can be used to add new items to the workload. Spawning of reaper threads will be handled for you automatically.
Since 0.1.1
Helper
mkListAction :: (item -> IO (Maybe item')) -> [item] -> IO ([item'] -> [item']) Source
A helper function for creating reaperAction
functions. You would
provide this function with a function to process a single work item and
return either a new work item, or Nothing
if the work item is
expired.
Since 0.1.1