Skip to content

Commit

Permalink
Implement atomicReadIORef and use it in getEpochState
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed May 17, 2024
1 parent 662abc7 commit 6c00851
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cardano-testnet/src/Testnet/Components/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ getEpochState :: MonadTest m
getEpochState EpochStateView{epochStateView} =
withFrozenCallStack $
H.byDurationM 0.5 15 "EpochStateView has not been initialized within 15 seconds" $
H.evalIO (readIORef epochStateView) >>= maybe H.failure pure
H.evalIO (atomicReadIORef epochStateView) >>= maybe H.failure pure

-- | Reads the IORef and updates it with the initial read value
atomicReadIORef :: IORef a -> IO a
atomicReadIORef ref =
atomicModifyIORef' ref (\refCurrentValue -> (refCurrentValue, refCurrentValue))

-- | Create a background thread listening for new epoch states. New epoch states are available to access
-- through 'EpochStateView', using query functions.
Expand Down

0 comments on commit 6c00851

Please sign in to comment.