From df6d2563bae3a20b9db1016c4ec2ac3cb0022790 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 9 Jun 2015 23:26:23 +0200 Subject: moved file management to the proper place --- src/Trivmix.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/Trivmix.hs') diff --git a/src/Trivmix.hs b/src/Trivmix.hs index 5dc213c..69fcea2 100644 --- a/src/Trivmix.hs +++ b/src/Trivmix.hs @@ -115,7 +115,8 @@ main = execParser opts >>= trivmix trivmix :: Options -> IO () trivmix Options{..} = do level <- newMVar initialLevel - withINotify $ \inotify -> do + let withFiles = foldl (.) id $ map (\f -> onStateFile f (show initialLevel ++ "\n")) levelFiles + withFiles $ withINotify $ \inotify -> do handleFiles inotify level levelFiles Jack.handleExceptions $ Jack.withClientDefault client $ \client' -> @@ -148,7 +149,7 @@ handleFiles inotify level files = do forkIO $ forever $ do -- Broadcast level changes and update all files readChan levelChanges' >>= writeLevel file addWatch inotify watchedAttrs file (const $ readLevel levelChanges level file) - sequence [onStateFile f (show initLevel ++ "\n") $ handleFile f | f <- files] + mapM handleFile files forkIO $ forever $ do readChan levelChanges >>= swapMVar level return () -- cgit v1.2.3