aboutsummaryrefslogtreecommitdiff
path: root/src/BangState.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/BangState.hs')
-rw-r--r--src/BangState.hs12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/BangState.hs b/src/BangState.hs
index 019f219..fabd9e7 100644
--- a/src/BangState.hs
+++ b/src/BangState.hs
@@ -11,7 +11,7 @@ module BangState (
import Codec.Compression.Brotli (compress)
import Control.Applicative ((<|>))
-import Control.Concurrent.STM.TChan
+import Control.Concurrent.STM.TQueue
import Control.Concurrent.STM.TVar
import Control.Monad (forever)
import Crypto.Hash (hashlazy, Digest, SHA512)
@@ -32,7 +32,7 @@ data BangState = BangState {
serializedBangs :: TVar ByteString,
brotliBangs :: TVar ByteString,
serializedHash :: TVar Text,
- syncFileNotifications :: TChan ()
+ syncFileNotifications :: TQueue ()
}
reserialize :: BangState -> STM ()
@@ -46,18 +46,16 @@ reserialize s = do
-- hash: for now, base64 of the first 120 bits of the SHA512 of the bangs
writeTVar (serializedHash s) $ decodeASCII $ Data.ByteString.take 20
$ convertToBase Base64 $ (hashlazy jsonBs :: Digest SHA512)
- writeTChan (syncFileNotifications s) ()
+ writeTQueue (syncFileNotifications s) ()
-- spawns a thread for syncing the current state to disk. do *NOT* use forkIO on this
-- function, it does so internally, and using forkIO may result in a (hard to trigger)
-- race condition
spawnFileSyncThread :: BangState -> IO ()
spawnFileSyncThread s = do
- readableChan <- atomically $ dupTChan (syncFileNotifications s)
-
_ <- forkIO $ forever $ do
nextBangs <- atomically $ do
- readTChan readableChan
+ readTQueue $ syncFileNotifications s
readTVar (ownBangs s)
atomicWriteFile "bangs.json" $ encode nextBangs
@@ -79,7 +77,7 @@ initBangState = do
<*> newTVarIO empty -- initially filled in by 'spawnFileSyncThread'
<*> newTVarIO empty -- same as above
<*> newTVarIO "" -- same as above
- <*> newBroadcastTChanIO
+ <*> newTQueueIO
spawnFileSyncThread s
return s