File tree 1 file changed +13
-10
lines changed
ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus
1 file changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -487,19 +487,22 @@ withTMVarAnd ::
487
487
IOLike m
488
488
=> StrictTMVar m a
489
489
-> (a -> STM m b ) -- ^ Additional STM action to run in the same atomically
490
- -- block as the TMVar is acquired
490
+ -- block as the TMVar is acquired
491
491
-> (a -> b -> m (c , a )) -- ^ Action
492
492
-> m c
493
493
withTMVarAnd tv guard f =
494
- bracketOnError
494
+ fst . fst <$> generalBracket
495
495
(atomically $ do
496
- i <- takeTMVar tv
497
- g <- guard i
498
- pure (i, g )
496
+ istate <- takeTMVar tv
497
+ guarded <- guard istate
498
+ pure (istate, guarded )
499
499
)
500
- (atomically . putTMVar tv . fst )
501
- (\ (s, g) -> do
502
- (x, s') <- f s g
503
- atomically $ putTMVar tv s'
504
- return x
500
+ (\ (origState, _) -> \ case
501
+ ExitCaseSuccess (_, newState)
502
+ -> atomically $ putTMVar tv newState
503
+ ExitCaseException _
504
+ -> atomically $ putTMVar tv origState
505
+ ExitCaseAbort
506
+ -> atomically $ putTMVar tv origState
505
507
)
508
+ (uncurry f)
You can’t perform that action at this time.
0 commit comments