From 9e5978006348cc78fd5aafbc010cb828b11c0503 Mon Sep 17 00:00:00 2001 From: Andrea Rossato Date: Wed, 27 Jun 2007 11:44:46 +0200 Subject: possibility to delay a thread for more than (maxBound :: Int) microseconds darcs-hash:20070627094446-d6583-a6eaac63d4cada455b5751010338f324508c87fb.gz --- XMobar.hs | 12 ++++++++---- 1 file 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 -- cgit v1.2.3