From 34134e5c237f901d1030a28037df15a5e02dc70e Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Sat, 15 Jul 2023 14:44:59 +0200 Subject: [PATCH] Fixed putMVar blocking file watcher The call to putMVar waits until the file watcher state MVar is empty. As it's never emptied, the file watcher hangs after watching the first sub directory (typically 'Config'). This is fixed by using modifyMVar_, which doesn't hang when the MVar is full --- IHP/IDE/FileWatcher.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IHP/IDE/FileWatcher.hs b/IHP/IDE/FileWatcher.hs index cf00d3e88..42711032b 100644 --- a/IHP/IDE/FileWatcher.hs +++ b/IHP/IDE/FileWatcher.hs @@ -42,7 +42,7 @@ startWatchingSubDirectory manager state path = do Just _ -> pure () Nothing -> do stop <- FS.watchTree manager path shouldActOnFileChange handleFileChange - putMVar state $ Map.insert path stop watchedDirectories + modifyMVar_ state (\map -> pure (Map.insert path stop map)) stopWatchingSubDirectory :: FileWatcherState -> FilePath -> IO () stopWatchingSubDirectory state path = do @@ -50,7 +50,7 @@ stopWatchingSubDirectory state path = do case Map.lookup path watchedDirectories of Just stop -> do stop - putMVar state $ Map.delete path watchedDirectories + modifyMVar_ state (\map -> pure (Map.delete path map)) Nothing -> pure () listWatchableDirectories :: IO [String]