@@ -37,6 +37,8 @@ module Control.Monad.Class.MonadSTM
37
37
, newTQueueDefault
38
38
, readTQueueDefault
39
39
, tryReadTQueueDefault
40
+ , peekTQueueDefault
41
+ , tryPeekTQueueDefault
40
42
, writeTQueueDefault
41
43
, isEmptyTQueueDefault
42
44
@@ -46,6 +48,8 @@ module Control.Monad.Class.MonadSTM
46
48
, newTBQueueDefault
47
49
, readTBQueueDefault
48
50
, tryReadTBQueueDefault
51
+ , peekTBQueueDefault
52
+ , tryPeekTBQueueDefault
49
53
, writeTBQueueDefault
50
54
, isEmptyTBQueueDefault
51
55
, isFullTBQueueDefault
@@ -131,13 +135,17 @@ class ( Monad stm
131
135
newTQueue :: stm (TQueue_ stm a )
132
136
readTQueue :: TQueue_ stm a -> stm a
133
137
tryReadTQueue :: TQueue_ stm a -> stm (Maybe a )
138
+ peekTQueue :: TQueue_ stm a -> stm a
139
+ tryPeekTQueue :: TQueue_ stm a -> stm (Maybe a )
134
140
writeTQueue :: TQueue_ stm a -> a -> stm ()
135
141
isEmptyTQueue :: TQueue_ stm a -> stm Bool
136
142
137
143
type TBQueue_ stm :: Type -> Type
138
144
newTBQueue :: Natural -> stm (TBQueue_ stm a )
139
145
readTBQueue :: TBQueue_ stm a -> stm a
140
146
tryReadTBQueue :: TBQueue_ stm a -> stm (Maybe a )
147
+ peekTBQueue :: TBQueue_ stm a -> stm a
148
+ tryPeekTBQueue :: TBQueue_ stm a -> stm (Maybe a )
141
149
flushTBQueue :: TBQueue_ stm a -> stm [a ]
142
150
writeTBQueue :: TBQueue_ stm a -> a -> stm ()
143
151
-- | @since 0.2.0.0
@@ -253,12 +261,16 @@ instance MonadSTMTx STM.STM where
253
261
newTQueue = STM. newTQueue
254
262
readTQueue = STM. readTQueue
255
263
tryReadTQueue = STM. tryReadTQueue
264
+ peekTQueue = STM. peekTQueue
265
+ tryPeekTQueue = STM. tryPeekTQueue
256
266
flushTBQueue = STM. flushTBQueue
257
267
writeTQueue = STM. writeTQueue
258
268
isEmptyTQueue = STM. isEmptyTQueue
259
269
newTBQueue = STM. newTBQueue
260
270
readTBQueue = STM. readTBQueue
261
271
tryReadTBQueue = STM. tryReadTBQueue
272
+ peekTBQueue = STM. peekTBQueue
273
+ tryPeekTBQueue = STM. tryPeekTBQueue
262
274
writeTBQueue = STM. writeTBQueue
263
275
lengthTBQueue = STM. lengthTBQueue
264
276
isEmptyTBQueue = STM. isEmptyTBQueue
@@ -462,6 +474,20 @@ isEmptyTQueueDefault (TQueue read write) = do
462
474
[] -> return True
463
475
_ -> return False
464
476
477
+ peekTQueueDefault :: MonadSTM m => TQueueDefault m a -> STM m a
478
+ peekTQueueDefault (TQueue read _write) = do
479
+ xs <- readTVar read
480
+ case xs of
481
+ (x: _) -> return x
482
+ _ -> retry
483
+
484
+ tryPeekTQueueDefault :: MonadSTM m => TQueueDefault m a -> STM m (Maybe a )
485
+ tryPeekTQueueDefault (TQueue read _write) = do
486
+ xs <- readTVar read
487
+ case xs of
488
+ (x: _) -> return (Just x)
489
+ _ -> return Nothing
490
+
465
491
--
466
492
-- Default TBQueue implementation in terms of TVars (used by sim)
467
493
--
@@ -514,6 +540,20 @@ tryReadTBQueueDefault (TBQueue rsize read _wsize write _size) = do
514
540
writeTVar read zs
515
541
return (Just z)
516
542
543
+ peekTBQueueDefault :: MonadSTM m => TBQueueDefault m a -> STM m a
544
+ peekTBQueueDefault (TBQueue _rsize read _wsize _write _size) = do
545
+ xs <- readTVar read
546
+ case xs of
547
+ (x: _) -> return x
548
+ _ -> retry
549
+
550
+ tryPeekTBQueueDefault :: MonadSTM m => TBQueueDefault m a -> STM m (Maybe a )
551
+ tryPeekTBQueueDefault (TBQueue _rsize read _wsize _write _size) = do
552
+ xs <- readTVar read
553
+ case xs of
554
+ (x: _) -> return (Just x)
555
+ _ -> return Nothing
556
+
517
557
writeTBQueueDefault :: MonadSTM m => TBQueueDefault m a -> a -> STM m ()
518
558
writeTBQueueDefault (TBQueue rsize _read wsize write _size) a = do
519
559
w <- readTVar wsize
0 commit comments