module System.IDontNotify where
import System.INotify
import Control.Concurrent (forkIO, threadDelay)
import Control.Concurrent.STM
import Control.Concurrent.STM.TSem
import Control.Monad (when, void)
neglectFile :: FilePath
-> Int
-> IO ()
neglectFile file time = do
debouncer <- atomically $ newTSem 0
notif <- initINotify
expectation <- newTVarIO (0 :: Int)
watcher <- addWatch notif [Modify] file $ \e -> void $ forkIO $ do
e' <- atomically $ do
modifyTVar expectation (+1)
readTVar expectation
threadDelay time
e'' <- readTVarIO expectation
when (e' == e'') $
atomically $ signalTSem debouncer
atomically $ waitTSem debouncer
removeWatch watcher
killINotify notif