summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrea Rossato <andrea.rossato@ing.unitn.it>2007-06-27 11:44:46 +0200
committerAndrea Rossato <andrea.rossato@ing.unitn.it>2007-06-27 11:44:46 +0200
commit9e5978006348cc78fd5aafbc010cb828b11c0503 (patch)
tree4b388709746a30e8fde6c68f4974c79998a9e45d
parent128e55e5a641d0e3ce4780f647c60d0e6756b1cc (diff)
downloadxmobar-9e5978006348cc78fd5aafbc010cb828b11c0503.tar.gz
xmobar-9e5978006348cc78fd5aafbc010cb828b11c0503.tar.bz2
possibility to delay a thread for more than (maxBound :: Int) microseconds
darcs-hash:20070627094446-d6583-a6eaac63d4cada455b5751010338f324508c87fb.gz
-rw-r--r--XMobar.hs12
1 files changed, 8 insertions, 4 deletions
diff --git a/XMobar.hs b/XMobar.hs
index a68f0b0..ff3a59b 100644
--- a/XMobar.hs
+++ b/XMobar.hs
@@ -261,8 +261,12 @@ initColor dpy c = (color_pixel . fst) `liftM` allocNamedColor dpy colormap c
io :: IO a -> Xbar a
io = liftIO
+-- | work arount the the Int max bound: since threadDelay takes an Int, it
+-- is not possible to set a thread delay grater than about 45 minutes.
+-- With a little recursion we solve the problem.
tenthSeconds :: Int -> IO ()
-tenthSeconds s =
- threadDelay n
- where n | (maxBound :: Int) `div` 100000 <= s = (maxBound :: Int)
- | otherwise = s * 100000
+tenthSeconds s | s >= x = do threadDelay y
+ tenthSeconds (x - s)
+ | otherwise = threadDelay (s * 100000)
+ where y = (maxBound :: Int)
+ x = y `div` 100000