From 2a71487437ca4afed6f35acc1e16c2e03bfc053c Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Tue, 13 Aug 2019 22:37:01 +0200 Subject: Refactor code from tenthSeconds to doEveryTenthSeconds A preparation for timer coalescing: tenthSeconds is just a sleep whereas doEveryTenthSeconds enables using a central timer and waiting for all monitors to update before refreshing the window. This commit is just a simple refactor, the actual timer coalescing code comes later. --- src/Xmobar/Run/Exec.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/Xmobar/Run/Exec.hs') diff --git a/src/Xmobar/Run/Exec.hs b/src/Xmobar/Run/Exec.hs index c8fcb9e..db7e7b4 100644 --- a/src/Xmobar/Run/Exec.hs +++ b/src/Xmobar/Run/Exec.hs @@ -17,7 +17,7 @@ -- ----------------------------------------------------------------------------- -module Xmobar.Run.Exec (Exec (..), tenthSeconds) where +module Xmobar.Run.Exec (Exec (..), tenthSeconds, doEveryTenthSeconds) where import Prelude import Data.Char @@ -34,6 +34,10 @@ tenthSeconds s | s >= x = do threadDelay (x * 100000) | otherwise = threadDelay (s * 100000) where x = (maxBound :: Int) `div` 100000 +doEveryTenthSeconds :: Int -> IO () -> IO () +doEveryTenthSeconds r action = go + where go = action >> tenthSeconds r >> go + class Show e => Exec e where alias :: e -> String alias e = takeWhile (not . isSpace) $ show e @@ -43,6 +47,6 @@ class Show e => Exec e where run _ = return "" start :: e -> (String -> IO ()) -> IO () start e cb = go - where go = run e >>= cb >> tenthSeconds (rate e) >> go + where go = doEveryTenthSeconds (rate e) $ run e >>= cb trigger :: e -> (Maybe SignalType -> IO ()) -> IO () trigger _ sh = sh Nothing -- cgit v1.2.3