summaryrefslogtreecommitdiff
path: root/Utility/TList.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-05-22 15:13:31 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-05-22 15:13:31 -0400
commit186434797dc41c815a07825072a63c9de1b47a25 (patch)
tree94ada4e3a7333a5e87557d5bc6ed51bb977f8e74 /Utility/TList.hs
parentdcbb9c33d5e82beb32a1068924f467d968ce9611 (diff)
add two long-running XMPP push threads, no more inversion of control
I hope this will be easier to reason about, and less buggy. It was certianly easier to write! An immediate benefit is that with a traversable queue of push requests to select from, the threads can be a lot fairer about choosing which client to service next.
Diffstat (limited to 'Utility/TList.hs')
-rw-r--r--Utility/TList.hs15
1 files changed, 11 insertions, 4 deletions
diff --git a/Utility/TList.hs b/Utility/TList.hs
index 716f72017..e4bb95498 100644
--- a/Utility/TList.hs
+++ b/Utility/TList.hs
@@ -23,7 +23,17 @@ newTList = newEmptyTMVar
{- Gets the contents of the TList. Blocks when empty.
- TList is left empty. -}
getTList :: TList a -> STM [a]
-getTList tlist = D.toList <$> takeTMVar tlist
+getTList tlist = D.toList <$> getTDList tlist
+
+getTDList :: TList a -> STM (D.DList a)
+getTDList = takeTMVar
+
+{- Replaces the contents of the TList. -}
+setTList :: TList a -> [a] -> STM ()
+setTList tlist = setTDList tlist . D.fromList
+
+setTDList :: TList a -> D.DList a -> STM ()
+setTDList tlist = modifyTList tlist . const
{- Takes anything currently in the TList, without blocking.
- TList is left empty. -}
@@ -54,6 +64,3 @@ snocTList tlist v = modifyTList tlist $ \dl -> D.snoc dl v
appendTList :: TList a -> [a] -> STM ()
appendTList tlist l = modifyTList tlist $ \dl -> D.append dl (D.fromList l)
-
-setTList :: TList a -> [a] -> STM ()
-setTList tlist l = modifyTList tlist $ const $ D.fromList l