Settings to control how values are updated.
This should be constructed using defaultUpdateSettings and record update syntax, e.g.:
let settings = defaultUpdateSettings { updateAction = Data.Time.Clock.getCurrentTime }
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27
Moduleauto-update-0.2.6Haskell2010
In a multithreaded environment, sharing results of actions can dramatically improve performance.
For example, web servers need to return the current time with each HTTP response.
For a high-volume server, it's much faster for a dedicated thread to run every
second, and write the current time to a shared IORef, than it is for each
request to make its own call to getCurrentTime.
But for a low-volume server, whose request frequency is less than once per
second, that approach will result in more calls to getCurrentTime than
necessary, and worse, kills idle GC.
This library solves that problem by allowing 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.
Example usage:
import Data.Time
import Control.AutoUpdate
getTime <- mkAutoUpdate defaultUpdateSettings
{ updateAction = Data.Time.Clock.getCurrentTime
, updateFreq = 1000000 -- The default frequency, once per second
}
currentTime <- getTime
For more examples, see the blog post introducing this library.
Settings to control how values are updated.
This should be constructed using defaultUpdateSettings and record update syntax, e.g.:
let settings = defaultUpdateSettings { updateAction = Data.Time.Clock.getCurrentTime }
Default value for creating an UpdateSettings.
Action to be performed to get the current value.
Default: does nothing.
Microseconds between update calls. Same considerations as
threadDelay apply.
Default: 1000000 microseconds (1 second)
Obsoleted field.
Label of the thread being forked.
Default: AutoUpdate