Skip to content

Commit 622f386

Browse files
authored
Merge pull request #6 from basvandijk/flushTQueue-write-only-when-necessary
flushTQueue: only perform writeTVar when necessary
2 parents 5ea70d4 + a77aae7 commit 622f386

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Control/Concurrent/STM/TQueue.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module Control.Concurrent.STM.TQueue (
4747
) where
4848

4949
import GHC.Conc
50-
50+
import Control.Monad (unless)
5151
import Data.Typeable (Typeable)
5252

5353
-- | 'TQueue' is an abstract type representing an unbounded FIFO channel.
@@ -115,8 +115,8 @@ flushTQueue :: TQueue a -> STM [a]
115115
flushTQueue (TQueue read write) = do
116116
xs <- readTVar read
117117
ys <- readTVar write
118-
writeTVar read []
119-
writeTVar write []
118+
unless (null xs) $ writeTVar read []
119+
unless (null ys) $ writeTVar write []
120120
return (xs ++ reverse ys)
121121

122122
-- | Get the next value from the @TQueue@ without removing it,

0 commit comments

Comments
 (0)