Make inotify optional.

Former-commit-id: 7b1776384f5755edf4d792a5c3c73ca4f5ef66e2
This commit is contained in:
David 2019-03-09 11:42:52 +01:00
commit 81d2176896
4 changed files with 43 additions and 4 deletions

View file

@ -0,0 +1,18 @@
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.