switch back to POSIXTime

turned out not to need Read MeterState
This commit is contained in:
Joey Hess 2020-12-04 13:54:33 -04:00
parent 31e417f351
commit e5b170aa1c
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -382,8 +382,8 @@ data Meter = Meter (MVar (Maybe Integer)) (MVar MeterState) (MVar String) Displa
data MeterState = MeterState data MeterState = MeterState
{ meterBytesProcessed :: BytesProcessed { meterBytesProcessed :: BytesProcessed
, meterTimeStamp :: Double , meterTimeStamp :: POSIXTime
} deriving (Show, Read) } deriving (Show)
type DisplayMeter = MVar String -> Maybe Integer -> MeterState -> MeterState -> IO () type DisplayMeter = MVar String -> Maybe Integer -> MeterState -> MeterState -> IO ()
@ -392,7 +392,7 @@ type RenderMeter = Maybe Integer -> MeterState -> MeterState -> String
-- | Make a meter. Pass the total size, if it's known. -- | Make a meter. Pass the total size, if it's known.
mkMeter :: Maybe Integer -> DisplayMeter -> IO Meter mkMeter :: Maybe Integer -> DisplayMeter -> IO Meter
mkMeter totalsize displaymeter = do mkMeter totalsize displaymeter = do
ts <- realToFrac <$> getPOSIXTime ts <- getPOSIXTime
Meter Meter
<$> newMVar totalsize <$> newMVar totalsize
<*> newMVar (MeterState zeroBytesProcessed ts) <*> newMVar (MeterState zeroBytesProcessed ts)
@ -405,7 +405,7 @@ setMeterTotalSize (Meter totalsizev _ _ _) = void . swapMVar totalsizev . Just
-- | Updates the meter, displaying it if necessary. -- | Updates the meter, displaying it if necessary.
updateMeter :: Meter -> MeterUpdate updateMeter :: Meter -> MeterUpdate
updateMeter (Meter totalsizev sv bv displaymeter) new = do updateMeter (Meter totalsizev sv bv displaymeter) new = do
now <- realToFrac <$> getPOSIXTime now <- getPOSIXTime
let curms = MeterState new now let curms = MeterState new now
oldms <- swapMVar sv curms oldms <- swapMVar sv curms
when (meterBytesProcessed oldms /= new) $ do when (meterBytesProcessed oldms /= new) $ do