diff options
author | Amir Saeid <amir@glgdgt.com> | 2021-07-06 21:40:02 +0100 |
---|---|---|
committer | Amir Saeid <amir@glgdgt.com> | 2021-07-13 08:40:45 +0100 |
commit | b36cf634ad5c075d6b1e73880433711a6786773c (patch) | |
tree | 13b561bae105cd8a0681f15820b38f01c6f40aa7 /src/Xmobar | |
parent | 084c16f5b3c49aa6bd1bc85bd14857e13cb20cac (diff) | |
download | xmobar-b36cf634ad5c075d6b1e73880433711a6786773c.tar.gz xmobar-b36cf634ad5c075d6b1e73880433711a6786773c.tar.bz2 |
Replace forkIO with bracket & Concurrent.Async
Diffstat (limited to 'src/Xmobar')
-rw-r--r-- | src/Xmobar/Plugins/Kraken.hs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/Xmobar/Plugins/Kraken.hs b/src/Xmobar/Plugins/Kraken.hs index 4a15199..8f2e1cc 100644 --- a/src/Xmobar/Plugins/Kraken.hs +++ b/src/Xmobar/Plugins/Kraken.hs @@ -3,8 +3,9 @@ module Xmobar.Plugins.Kraken (Kraken(..)) where -import Control.Concurrent -import Control.Exception (catch) +import Control.Concurrent (MVar, newEmptyMVar, putMVar, takeMVar) +import Control.Concurrent.Async (async, cancel) +import Control.Exception (bracket, catch) import Control.Monad (forever, mzero, void, when) import Data.Aeson import Data.Aeson.Types (Parser, typeMismatch) @@ -28,14 +29,14 @@ instance Exec Kraken where alias (Kraken _ a) = a start (Kraken ps _) cb = do mvar <- newEmptyMVar - forkIO $ reconnectOnConnectionClose $ wsClientApp ps mvar - let loop mv p = do - v <- takeMVar mv - let g = Map.insert (unpack $ fst v) (snd v) p - cb (display g) - loop mv g - - loop mvar (Map.fromList $ zip ps (repeat 0.0)) + bracket (async $ reconnectOnConnectionClose $ wsClientApp ps mvar) cancel $ \_ -> do + let loop mv p = do + v <- takeMVar mv + let g = Map.insert (unpack $ fst v) (snd v) p + cb (display g) + loop mv g + + loop mvar (Map.fromList $ zip ps (repeat 0.0)) where display :: Map.Map String Double -> String |