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

Safe Haskell | Safe-Inferred
Language | Haskell2010

Control.AutoUpdate.Internal

Contents

- Debugging

Synopsis

- data UpdateState a = UpdateState {
  - usUpdateAction_ :: a -> IO a
  - usLastResult_ :: IORef a
  - usIntervalMicro_ :: Int
  - usTimeHasCome_ :: TVar Bool
  - usDeleteTimeout_ :: IORef (IO ())
  }
- mkClosableAutoUpdate :: UpdateSettings a -> IO (IO a, IO ())
- mkClosableAutoUpdate' :: UpdateSettings a -> IO (IO a, IO (), UpdateState a)

# Debugging

data UpdateState a Source #

Constructors

UpdateState |

Fields

- usUpdateAction_ :: a -> IO a
- usLastResult_ :: IORef a
- usIntervalMicro_ :: Int
- usTimeHasCome_ :: TVar Bool
- usDeleteTimeout_ :: IORef (IO ())

mkClosableAutoUpdate :: UpdateSettings a -> IO (IO a, IO ()) Source #

    >>> iref <- newIORef (0 :: Int)
    >>> action = modifyIORef iref (+ 1) >> readIORef iref
    >>> (getValue, closeState) <- mkClosableAutoUpdate $ defaultUpdateSettings { updateFreq = 200_000, updateAction = action }
    >>> getValue
    1
    >>> threadDelay 100_000 >> getValue
    1
    >>> threadDelay 200_000 >> getValue
    2
    >>> closeState

mkClosableAutoUpdate' :: UpdateSettings a -> IO (IO a, IO (), UpdateState a) Source #

provide `UpdateState` for debugging