auto-update-0.1.1.5: Efficiently run periodic, on-demand actions

Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Reaper

Contents

Description

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.

Synopsis

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 items. 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

Number of microseconds to delay between calls of reaperAction.

Default: 30 seconds.

Since 0.1.1

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.

Constructors

Reaper 

Fields

reaperAdd :: item -> IO ()

Adding an item to the workload

reaperRead :: IO workload

Reading workload.

reaperStop :: IO workload

Stopping the reaper thread if exists. The current workload is returned.

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