1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE QuasiQuotes #-}
module Main where
import Control.Concurrent
import Data.String.Interpolate
import System.FSNotify
import System.FilePath
import UnliftIO.Temporary
main :: IO ()
main = do
withSystemTempDirectory "fsnotify-foo" $ \dir -> do
putStrLn [i|Starting watch on dir: #{dir}|]
let conf = defaultConfig
withManagerConf conf $ \mgr -> do
stop <- watchDir mgr dir (const True) $ \ev -> do
putStrLn [i|Got event: #{ev}|]
threadDelay 3_000_000
putStrLn [i|Writing to #{dir </> "bar"}|]
writeFile (dir </> "bar") "asdf"
threadDelay 3_000_000
putStrLn [i|Stopping|]
stop
putStrLn [i|Stopped|]
threadDelay 3_000_000
putStrLn [i|Exited withManagerConf|]
threadDelay 3_000_000
|