add derives needed for use with Yesod, and fix a bug
This commit is contained in:
parent
109dc122da
commit
5be5cb219f
1 changed files with 4 additions and 2 deletions
|
@ -14,6 +14,7 @@
|
||||||
module Utility.NotificationBroadcaster (
|
module Utility.NotificationBroadcaster (
|
||||||
NotificationBroadcaster,
|
NotificationBroadcaster,
|
||||||
NotificationHandle,
|
NotificationHandle,
|
||||||
|
NotificationId,
|
||||||
newNotificationBroadcaster,
|
newNotificationBroadcaster,
|
||||||
newNotificationHandle,
|
newNotificationHandle,
|
||||||
notificationHandleToId,
|
notificationHandleToId,
|
||||||
|
@ -31,6 +32,7 @@ import Control.Concurrent.SampleVar
|
||||||
type NotificationBroadcaster = TMVar [SampleVar ()]
|
type NotificationBroadcaster = TMVar [SampleVar ()]
|
||||||
|
|
||||||
newtype NotificationId = NotificationId Int
|
newtype NotificationId = NotificationId Int
|
||||||
|
deriving (Read, Eq, Ord)
|
||||||
|
|
||||||
instance Show NotificationId where
|
instance Show NotificationId where
|
||||||
show (NotificationId i) = show i
|
show (NotificationId i) = show i
|
||||||
|
@ -39,7 +41,7 @@ instance Show NotificationId where
|
||||||
data NotificationHandle = NotificationHandle NotificationBroadcaster NotificationId
|
data NotificationHandle = NotificationHandle NotificationBroadcaster NotificationId
|
||||||
|
|
||||||
newNotificationBroadcaster :: IO NotificationBroadcaster
|
newNotificationBroadcaster :: IO NotificationBroadcaster
|
||||||
newNotificationBroadcaster = atomically (newTMVar [])
|
newNotificationBroadcaster = atomically $ newTMVar []
|
||||||
|
|
||||||
{- Allocates a notification handle for a client to use. -}
|
{- Allocates a notification handle for a client to use. -}
|
||||||
newNotificationHandle :: NotificationBroadcaster -> IO NotificationHandle
|
newNotificationHandle :: NotificationBroadcaster -> IO NotificationHandle
|
||||||
|
@ -50,7 +52,7 @@ newNotificationHandle b = NotificationHandle
|
||||||
addclient = do
|
addclient = do
|
||||||
s <- newEmptySampleVar
|
s <- newEmptySampleVar
|
||||||
atomically $ do
|
atomically $ do
|
||||||
l <- readTMVar b
|
l <- takeTMVar b
|
||||||
putTMVar b $ l ++ [s]
|
putTMVar b $ l ++ [s]
|
||||||
return $ NotificationId $ length l
|
return $ NotificationId $ length l
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue