summaryrefslogtreecommitdiff
path: root/Utility/NotificationBroadcaster.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-07-28 16:01:50 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-07-28 16:09:34 -0400
commita17fde22fabdb706086ac945bc331e32527b58bd (patch)
treec87502a0ec9121c6352b5597a56ee84cd4c5a6ac /Utility/NotificationBroadcaster.hs
parentca478b7bcb48fee0d1a97340e6ea5da8e97074f0 (diff)
add a NotificationBroadcaster to DaemonStatus
First use of it is to make the status checkpointer thread block until there is really a change to the status.
Diffstat (limited to 'Utility/NotificationBroadcaster.hs')
-rw-r--r--Utility/NotificationBroadcaster.hs26
1 files changed, 13 insertions, 13 deletions
diff --git a/Utility/NotificationBroadcaster.hs b/Utility/NotificationBroadcaster.hs
index 51b321752..caa13bbac 100644
--- a/Utility/NotificationBroadcaster.hs
+++ b/Utility/NotificationBroadcaster.hs
@@ -11,10 +11,10 @@
- Licensed under the GNU GPL version 3 or higher.
-}
-module Assistant.NotificationBroadCaster (
- NotificationBroadCaster,
+module Utility.NotificationBroadcaster (
+ NotificationBroadcaster,
NotificationHandle,
- newNotificationBroadCaster,
+ newNotificationBroadcaster,
newNotificationHandle,
notificationHandleToId,
notificationHandleFromId,
@@ -28,21 +28,21 @@ import Control.Concurrent.STM
import Control.Concurrent.SampleVar
{- One SampleVar per client. The TMVar is never empty, so never blocks. -}
-type NotificationBroadCaster = TMVar [SampleVar ()]
+type NotificationBroadcaster = TMVar [SampleVar ()]
{- Handle given out to an individual client. -}
-data NotificationHandle = NotificationHandle NotificationBroadCaster Int
+data NotificationHandle = NotificationHandle NotificationBroadcaster Int
-newNotificationBroadCaster :: IO NotificationBroadCaster
-newNotificationBroadCaster = atomically (newTMVar [])
+newNotificationBroadcaster :: IO NotificationBroadcaster
+newNotificationBroadcaster = atomically (newTMVar [])
{- Allocates a notification handle for a client to use. -}
-newNotificationHandle :: NotificationBroadCaster -> IO NotificationHandle
+newNotificationHandle :: NotificationBroadcaster -> IO NotificationHandle
newNotificationHandle b = NotificationHandle
<$> pure b
- <*> addclient b
+ <*> addclient
where
- addclient b = do
+ addclient = do
s <- newEmptySampleVar
atomically $ do
l <- readTMVar b
@@ -54,13 +54,13 @@ newNotificationHandle b = NotificationHandle
notificationHandleToId :: NotificationHandle -> Int
notificationHandleToId (NotificationHandle _ i) = i
-{- Given a NotificationBroadCaster, and an Int identifier, recreates the
+{- Given a NotificationBroadcaster, and an Int identifier, recreates the
- NotificationHandle. -}
-notificationHandleFromId :: NotificationBroadCaster -> Int -> NotificationHandle
+notificationHandleFromId :: NotificationBroadcaster -> Int -> NotificationHandle
notificationHandleFromId = NotificationHandle
{- Sends a notification to all clients. -}
-sendNotification :: NotificationBroadCaster -> IO ()
+sendNotification :: NotificationBroadcaster -> IO ()
sendNotification b = do
l <- atomically $ readTMVar b
mapM_ notify l