mirror of
https://github.com/reanimate/reanimate.git
synced 2026-09-15 18:12:20 +00:00
Make inotify optional.
Former-commit-id: 7b1776384f5755edf4d792a5c3c73ca4f5ef66e2
This commit is contained in:
parent
da1205861a
commit
81d2176896
4 changed files with 43 additions and 4 deletions
18
posix/Reanimate/FileWatch.hs
Normal file
18
posix/Reanimate/FileWatch.hs
Normal 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.
|
||||
Loading…
Reference in a new issue