From 56928c6f5602461a06211f2161fa845d17ba159b Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Mon, 18 Jun 2018 08:40:23 -0400 Subject: Implement some kind of announcer shutdown Probably this crashes the program when the tchan is used. Fixable. --- Announcer.hs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'Announcer.hs') diff --git a/Announcer.hs b/Announcer.hs index 7d1d605d..e0f8b47e 100644 --- a/Announcer.hs +++ b/Announcer.hs @@ -153,7 +153,9 @@ readTChanTimeout timeout pktChannel = do toMicroseconds :: POSIXTime -> Int toMicroseconds = undefined -listener :: TChan KPS -> IO () +data SchedulerCommand = ShutdownScheduler | ScheduledAction KPS + +listener :: TChan SchedulerCommand -> IO () listener chan = relisten PSQ.empty where note :: String -> IO () @@ -162,14 +164,17 @@ listener chan = relisten PSQ.empty case minView queue of Nothing -> do note "queue empty - listening indefinitely" - (k, p, s) <- atomically $ readTChan chan - note "handling new event" - relisten $ PSQ.insert' k s p queue + atomically (readTChan chan) >>= \case + ShutdownScheduler -> return () + ScheduledAction (k, p, s) -> do + note "handling new event" + relisten $ PSQ.insert' k s p queue Just ((k, p, s), queue') -> do note "queue full - listening with timeout" now <- getPOSIXTime readTChanTimeout (p - now) chan >>= \case - Just (k, p, s) -> do + Just (ShutdownScheduler) -> return () + Just (ScheduledAction (k, p, s)) -> do note "handling new event (event occurred before timeout)" relisten $ PSQ.insert' k s p queue Nothing -> do -- cgit v1.2.3