mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-11-26 09:06:56 +03:00
BChan: add writeBChanNonBlocking, raise STM lower bound to 2.4.3
This commit is contained in:
parent
5baad2bc63
commit
e0fdfc7786
@ -101,7 +101,7 @@ library
|
||||
config-ini,
|
||||
vector,
|
||||
contravariant,
|
||||
stm >= 2.4,
|
||||
stm >= 2.4.3,
|
||||
text,
|
||||
text-zipper >= 0.7.1,
|
||||
template-haskell,
|
||||
|
@ -2,6 +2,7 @@ module Brick.BChan
|
||||
( BChan
|
||||
, newBChan
|
||||
, writeBChan
|
||||
, writeBChanNonBlocking
|
||||
, readBChan
|
||||
, readBChan2
|
||||
)
|
||||
@ -26,6 +27,16 @@ newBChan size = atomically $ BChan <$> newTBQueue (fromIntegral size)
|
||||
writeBChan :: BChan a -> a -> IO ()
|
||||
writeBChan (BChan q) a = atomically $ writeTBQueue q a
|
||||
|
||||
-- | Attempts to write a value to a @BChan@. If the channel has room,
|
||||
-- the value is written and this returns 'True'. Otherwise this returns
|
||||
-- 'False' and returns immediately.
|
||||
writeBChanNonBlocking :: BChan a -> a -> IO Bool
|
||||
writeBChanNonBlocking (BChan q) a = atomically $ do
|
||||
f <- isFullTBQueue q
|
||||
if f
|
||||
then return False
|
||||
else writeTBQueue q a >> return True
|
||||
|
||||
-- | Reads the next value from the @BChan@; blocks if necessary.
|
||||
readBChan :: BChan a -> IO a
|
||||
readBChan (BChan q) = atomically $ readTBQueue q
|
||||
|
Loading…
Reference in New Issue
Block a user