Skip to content

Commit

Permalink
Documented a function for clearing a message queue for future use
Browse files Browse the repository at this point in the history
  • Loading branch information
rehno-lindeque committed Jun 5, 2012
1 parent 4e26851 commit d36826a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/STM/Messages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module STM.Messages (Messages, newIO, enqueueMessage) where
-- Standard modules
import Control.Concurrent.STM (atomically)
import Control.Concurrent.STM.TChan
import Control.Monad (unless)

-- Application modules
import Message
Expand All @@ -15,4 +16,16 @@ newIO = newTChanIO

-- Add a message to the queue as a single atomic transaction
enqueueMessage :: Messages -> Message -> IO ()
enqueueMessage messages = atomically . (writeTChan messages)
enqueueMessage m = atomically . (writeTChan m)

{-- Clear all the messages from the queue without processing them using multiple atomic operations
clearMessages :: Messages -> IO ()
clearMessages m = do
done <- atomically $ do
isEmpty <- isEmptyTChan m
unless isEmpty $ readTChan m >> return ()
return isEmpty
if done
then return ()
else clearMessages m
--}

0 comments on commit d36826a

Please sign in to comment.