From 6ab59438123d00b02b5a04235102df7af2926cd4 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 28 May 2011 12:41:37 +0200 Subject: Remove inotify bindings for now --- src/Hakyll/Web/Preview/Poll.hs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/Hakyll/Web/Preview/Poll.hs (limited to 'src/Hakyll/Web/Preview') diff --git a/src/Hakyll/Web/Preview/Poll.hs b/src/Hakyll/Web/Preview/Poll.hs new file mode 100644 index 0000000..83ec54a --- /dev/null +++ b/src/Hakyll/Web/Preview/Poll.hs @@ -0,0 +1,34 @@ +-- | Interval-based implementation of preview polling +-- +module Hakyll.Web.Preview.Poll + ( previewPoll + ) where + +import Control.Applicative ((<$>)) +import Control.Concurrent (threadDelay) +import Control.Monad (filterM) +import System.Time (getClockTime) +import System.Directory (getModificationTime, doesFileExist) + +import Hakyll.Core.Configuration + +-- | A preview thread that periodically recompiles the site. +-- +previewPoll :: HakyllConfiguration -- ^ Configuration + -> IO [FilePath] -- ^ Updating action + -> IO () -- ^ Can block forever +previewPoll _ update = do + time <- getClockTime + loop time =<< update + where + delay = 1000000 + loop time files = do + threadDelay delay + files' <- filterM doesFileExist files + filesTime <- case files' of + [] -> return time + _ -> maximum <$> mapM getModificationTime files' + + if filesTime > time || files' /= files + then loop filesTime =<< update + else loop time files' -- cgit v1.2.3