Skip to content

Commit d5a82bb

Browse files
committed
Define WithArrivalTime combinator
1 parent f2e90d6 commit d5a82bb

File tree

1 file changed

+26
-0
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/BlockchainTime/WallClock

1 file changed

+26
-0
lines changed

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/BlockchainTime/WallClock/Types.hs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE DeriveAnyClass #-}
3+
{-# LANGUAGE DeriveGeneric #-}
24
{-# LANGUAGE DerivingVia #-}
35

46
module Ouroboros.Consensus.BlockchainTime.WallClock.Types
@@ -15,6 +17,10 @@ module Ouroboros.Consensus.BlockchainTime.WallClock.Types
1517
-- * Get current time (as 'RelativeTime')
1618
, SystemTime (..)
1719

20+
-- * Attach an arrival time (as 'RelativeTime') to an object
21+
, WithArrivalTime (..)
22+
, addArrivalTime
23+
1824
-- * Slot length
1925
, getSlotLength
2026
, mkSlotLength
@@ -31,6 +37,7 @@ module Ouroboros.Consensus.BlockchainTime.WallClock.Types
3137

3238
import Cardano.Slotting.Time
3339
import Data.Time.Clock (NominalDiffTime)
40+
import GHC.Generics (Generic)
3441
import NoThunks.Class (NoThunks, OnlyCheckWhnfNamed (..))
3542

3643
addRelTime :: NominalDiffTime -> RelativeTime -> RelativeTime
@@ -60,3 +67,22 @@ data SystemTime m = SystemTime
6067
-- to reach 'SystemStart'. In tests this does nothing.
6168
}
6269
deriving NoThunks via OnlyCheckWhnfNamed "SystemTime" (SystemTime m)
70+
71+
{-------------------------------------------------------------------------------
72+
Attach an arrival time (as RelativeTime) to an object
73+
-------------------------------------------------------------------------------}
74+
75+
-- | WithArrivalTime
76+
data WithArrivalTime a = WithArrivalTime
77+
{ getArrivalTime :: !RelativeTime
78+
-- ^ The time at which the object arrived
79+
, forgetArrivalTime :: !a
80+
-- ^ The object without its arrival time
81+
}
82+
deriving (Show, Eq, Ord, Generic, NoThunks)
83+
84+
-- | Add an arrival time to an object
85+
addArrivalTime :: Monad m => SystemTime m -> a -> m (WithArrivalTime a)
86+
addArrivalTime systemTime a = do
87+
t <- systemTimeCurrent systemTime
88+
return (WithArrivalTime t a)

0 commit comments

Comments
 (0)