mirror of
https://github.com/reanimate/reanimate.git
synced 2026-09-15 18:12:20 +00:00
18 lines
477 B
Haskell
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.
|