{-|
Module      : Control.Concurrent.Async.Refresh.Types
Description : This module contains the type definitions for the async-refresh package.
Copyright   : (c) Moritz Schulte, 2017
License     : BSD3
Maintainer  : [email protected]
Stability   : experimental
Portability : POSIX
-}

module Control.Concurrent.Async.Refresh.Types where

import           Control.Concurrent.Async.Refresh.Prelude

-- | Type synonym for async refresh callbacks.
type AsyncRefreshCallback m a = Either SomeException (RefreshResult a) -> m ()

-- | Data type defining an async refresh configuration.
data AsyncRefreshConf m a =
  AsyncRefreshConf
  { forall (m :: * -> *) a. AsyncRefreshConf m a -> Int
_asyncRefreshConfDefaultInterval :: Int                      -- ^ In milliseconds.
  , forall (m :: * -> *) a. AsyncRefreshConf m a -> m (RefreshResult a)
_asyncRefreshConfAction          :: m (RefreshResult a)      -- ^ Action implementing the refreshing.
  , forall (m :: * -> *) a. AsyncRefreshConf m a -> Double
_asyncRefreshConfFactor          :: Double                   -- ^ Refresh factor.
  , forall (m :: * -> *) a.
AsyncRefreshConf m a -> AsyncRefreshCallback m a
_asyncRefreshConfCallback        :: AsyncRefreshCallback m a -- ^ To be called after refreshing.
  , forall (m :: * -> *) a. AsyncRefreshConf m a -> Maybe Text
_asyncRefreshConfLabel           :: Maybe Text               -- ^ Human readable label.
  }

-- | Data type denoting a running async refresher.
newtype AsyncRefresh =
  AsyncRefresh { AsyncRefresh -> Async ()
asyncRefreshAsync       :: Async () }

-- | Data type returned by async refresh actions.
data RefreshResult a =
  RefreshResult { forall a. RefreshResult a -> a
refreshResult :: a         -- ^ Actual result.
                , forall a. RefreshResult a -> Maybe Int
refreshExpiry :: Maybe Int -- ^ In milliseconds.
                } deriving (Int -> RefreshResult a -> ShowS
[RefreshResult a] -> ShowS
RefreshResult a -> String
(Int -> RefreshResult a -> ShowS)
-> (RefreshResult a -> String)
-> ([RefreshResult a] -> ShowS)
-> Show (RefreshResult a)
forall a. Show a => Int -> RefreshResult a -> ShowS
forall a. Show a => [RefreshResult a] -> ShowS
forall a. Show a => RefreshResult a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> RefreshResult a -> ShowS
showsPrec :: Int -> RefreshResult a -> ShowS
$cshow :: forall a. Show a => RefreshResult a -> String
show :: RefreshResult a -> String
$cshowList :: forall a. Show a => [RefreshResult a] -> ShowS
showList :: [RefreshResult a] -> ShowS
Show)