reanimate/posix/Reanimate/FileWatch.hs
David 81d2176896 Make inotify optional.
Former-commit-id: 7b1776384f5755edf4d792a5c3c73ca4f5ef66e2
2019-03-09 11:42:52 +01:00

18 lines
477 B
Haskell

module Reanimate.FileWatch
( watchFile ) where
import Control.Concurrent
import System.Directory
watchFile :: FilePath -> IO () -> IO ()
watchFile path handler = do
t0 <- getModificationTime path
forkIO $ loop t0
return ()
where
loop lastModTime = do
t1 <- getModificationTime path
if t1 /= lastModTime
then handler >> loop t1
else threadDelay (10^3 * delay) >> loop lastModTime
delay = 1000 -- pool delay in ms.