alarmclock 0.2.0.3 → 0.2.0.4
raw patch · 2 files changed
+11/−17 lines, 2 filesdep +unbounded-delaysPVP ok
version bump matches the API change (PVP)
Dependencies added: unbounded-delays
API changes (from Hackage documentation)
Files
- alarmclock.cabal +2/−1
- src/Control/Concurrent/AlarmClock.hs +9/−16
alarmclock.cabal view
@@ -1,5 +1,5 @@ name: alarmclock-version: 0.2.0.3+version: 0.2.0.4 synopsis: Wake up and perform an action at a certain time. description: Wake up and perform an action at a certain time. homepage: https://bitbucket.org/davecturner/alarmclock@@ -18,6 +18,7 @@ base >=4.7 && <4.8 , stm , time+ , unbounded-delays hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall
src/Control/Concurrent/AlarmClock.hs view
@@ -31,13 +31,13 @@ , isAlarmSetSTM ) where -import Control.Applicative-import Control.Concurrent-import Control.Concurrent.STM-import Control.Exception-import Control.Monad-import Data.Time-import System.Timeout+import Control.Applicative ((<$>), (<*>))+import Control.Concurrent (forkIO)+import Control.Concurrent.STM (STM, atomically, retry, TVar, newTVar, writeTVar, readTVar, modifyTVar')+import Control.Concurrent.Timeout (timeout)+import Control.Exception (finally)+import Control.Monad (void)+import Data.Time (UTCTime, diffUTCTime, getCurrentTime) {-| An 'AlarmClock' is a device for running an action at (or shortly after) a certain time. -} data AlarmClock = AlarmClock@@ -119,20 +119,13 @@ dt <- diffUTCTime wakeUpTime <$> getCurrentTime if dt <= 0 then actAndContinue- else timeout (fromIntegral $ min maxDelay $ ceiling $ 1000000 * dt)+ else timeout (ceiling $ 1000000 * dt) (readNextAlarmSetting ac) >>= \case- Nothing -> do- t' <- getCurrentTime- if t' < wakeUpTime- then wakeNoLaterThan wakeUpTime- else actAndContinue+ Nothing -> actAndContinue Just newSetting -> go newSetting actAndContinue = do atomically $ writeTVar (acIsSet ac) False wakeUpAction loop--maxDelay :: Integer-maxDelay = fromIntegral (maxBound :: Int)