packages feed

auto-update-unliftio-0.1.0: src/UnliftIO/AutoUpdate/Types.hs

module UnliftIO.AutoUpdate.Types where

import Data.Functor.Identity

{- | 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' }
 @

 @since 0.1.0
-}
data UpdateSettings m a = UpdateSettings
  { updateFreq :: Int
  -- ^ Microseconds between update calls. Same considerations as
  -- 'Control.Concurrent.threadDelay' apply.
  --
  -- Default: 1000000 microseconds (1 second)
  --
  -- @since 0.1.0
  , updateAction :: m a
  -- ^ Action to be performed to get the current value.
  --
  -- Default: does nothing.
  --
  -- @since 0.1.0
  , updateThreadName :: String
  -- ^ Label of the thread being forked.
  --
  -- Default: @"AutoUpdate"@
  --
  -- @since 0.1.0
  }

{- | Default value for creating an 'UpdateSettings'.

 @since 0.1.0
-}
defaultUpdateSettings :: UpdateSettings Identity ()
defaultUpdateSettings =
  UpdateSettings
    { updateFreq = 1000000
    , updateAction = pure ()
    , updateThreadName = "AutoUpdate"
    }