@@ -6,12 +6,12 @@
6-- second, and write the current time to a shared 'IORef', than it is for each
6-- second, and write the current time to a shared 'IORef', than it is for each
7-- request to make its own call to 'getCurrentTime'.
7-- request to make its own call to 'getCurrentTime'.
9−-- But for a low-volume server, whose request frequency is less than once per
9+-- But for a low-volume server, whose request frequency is less than once per
10−-- second, that approach will result in /more/ calls to 'getCurrentTime' than
10+-- second, that approach will result in /more/ calls to 'getCurrentTime' than
11-- necessary, and worse, kills idle GC.
11-- necessary, and worse, kills idle GC.
13-- This library solves that problem by allowing you to define actions which will
13-- This library solves that problem by allowing you to define actions which will
14−-- either be performed by a dedicated thread, or, in times of low volume, will
14+-- either be performed by a dedicated thread, or, in times of low volume, will
15-- be executed by the calling thread.
15-- be executed by the calling thread.
17-- Example usage:
17-- Example usage:
@@ -98,16 +98,19 @@ data UpdateSettings a = UpdateSettings
98 -- @since 0.1.0
98 -- @since 0.1.0
101+-- | Generate an action which will either read from an automatically
102+-- updated value, or run the update action in the current thread.
101mkAutoUpdate :: UpdateSettings a -> IO (IO a)
105mkAutoUpdate :: UpdateSettings a -> IO (IO a)
102mkAutoUpdate us = mkAutoUpdateHelper us Nothing
106mkAutoUpdate us = mkAutoUpdateHelper us Nothing
108+-- | Generate an action which will either read from an automatically
109+-- updated value, or run the update action in the current thread if
110+-- the first time or the provided modify action after that.
104mkAutoUpdateWithModify :: UpdateSettings a -> (a -> IO a) -> IO (IO a)
111mkAutoUpdateWithModify :: UpdateSettings a -> (a -> IO a) -> IO (IO a)
105mkAutoUpdateWithModify us f = mkAutoUpdateHelper us (Just f)
112mkAutoUpdateWithModify us f = mkAutoUpdateHelper us (Just f)
107−-- | Generate an action which will either read from an automatically
108−-- updated value, or run the update action in the current thread.
111mkAutoUpdateHelper :: UpdateSettings a -> Maybe (a -> IO a) -> IO (IO a)
114mkAutoUpdateHelper :: UpdateSettings a -> Maybe (a -> IO a) -> IO (IO a)
112mkAutoUpdateHelper us updateActionModify = do
115mkAutoUpdateHelper us updateActionModify = do
113 -- A baton to tell the worker thread to generate a new value.
116 -- A baton to tell the worker thread to generate a new value.