Skip to content

Commit 9c4ef3f

Browse files
committed
Provide a MonadInspectMVar instance for IOSim.
1 parent fbfe11f commit 9c4ef3f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

io-sim/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Revsion history of io-sim
22

3+
## next version
4+
5+
### Non breaking changes
6+
7+
* Provide `MonadInspectMVar` instance for `IOSim`.
8+
39
## 1.1.0.0
410

511
### Non breaking changes

io-sim/src/Control/Monad/IOSim/Types.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,14 @@ instance MonadMVar (IOSim s) where
567567
tryReadMVar = tryReadMVarDefault
568568
isEmptyMVar = isEmptyMVarDefault
569569

570+
instance MonadInspectMVar (IOSim s) where
571+
type InspectMVarMonad (IOSim s) = ST s
572+
inspectMVar p (MVar tvar) = do
573+
st <- inspectTVar p tvar
574+
case st of
575+
MVarEmpty _ _ -> pure Nothing
576+
MVarFull x _ -> pure (Just x)
577+
570578
data Async s a = Async !ThreadId (STM s (Either SomeException a))
571579

572580
instance Eq (Async s a) where

0 commit comments

Comments
 (0)