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

Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.AutoUpdate

Contents

Description

A common problem is the desire to have an action run at a scheduled interval, but only if it is needed. For example, instead of having every web request result in a new getCurrentTime call, we'd like to have a single worker thread run every second, updating an IORef. However, if the request frequency is less than once per second, this is a pessimization, and worse, kills idle GC.

This library allows you to define actions which will either be performed by a dedicated thread or, in times of low volume, will be executed by the calling thread.

Synopsis

Type

data UpdateSettings a Source

Settings to control how values are updated.

This should be constructed using defaultUpdateSettings and record update syntax, e.g.:

let set = defaultUpdateSettings { updateAction = getCurrentTime }

Since 0.1.0

defaultUpdateSettings :: UpdateSettings () Source

Default value for creating an UpdateSettings.

Since 0.1.0

Accessors

updateFreq :: UpdateSettings a -> Int Source

Microseconds between update calls. Same considerations as threadDelay apply.

Default: 1 second (1000000)

Since 0.1.0

updateSpawnThreshold :: UpdateSettings a -> Int Source

NOTE: This value no longer has any effect, since worker threads are dedicated instead of spawned on demand.

Previously, this determined: How many times the data must be requested before we decide to spawn a dedicated thread.

Default: 3

Since 0.1.0

updateAction :: UpdateSettings a -> IO a Source

Action to be performed to get the current value.

Default: does nothing.

Since 0.1.0

Creation

mkAutoUpdate :: UpdateSettings a -> IO (IO a) Source

Generate an action which will either read from an automatically updated value, or run the update action in the current thread.

Since 0.1.0