summaryrefslogtreecommitdiff
path: root/src-interval
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-03-01 14:50:41 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-03-01 14:50:41 +0100
commit90b25105830d6e4b0943ab55f9317bd142533acf (patch)
tree6eefb80a8a84724e70539dd8fa449530f7b17fe0 /src-interval
parent8ef5a3ed0307be5d34a9564d02af3ed494f8e228 (diff)
parent8b727b994d482d593046f9b01a5c40b97c166d62 (diff)
downloadhakyll-90b25105830d6e4b0943ab55f9317bd142533acf.tar.gz
Merge branch 'hakyll3'
Conflicts: hakyll.cabal src/Text/Hakyll/Tags.hs
Diffstat (limited to 'src-interval')
-rw-r--r--src-interval/Hakyll/Web/Preview/Poll.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src-interval/Hakyll/Web/Preview/Poll.hs b/src-interval/Hakyll/Web/Preview/Poll.hs
new file mode 100644
index 0000000..ec6df0c
--- /dev/null
+++ b/src-interval/Hakyll/Web/Preview/Poll.hs
@@ -0,0 +1,36 @@
+-- | Interval-based implementation of preview polling, for the platforms which
+-- are not supported by inotify.
+--
+module Hakyll.Web.Preview.Poll
+ ( previewPoll
+ ) where
+
+import Control.Applicative ((<$>))
+import Control.Concurrent (threadDelay)
+import Control.Monad (when)
+import System.Time (getClockTime)
+import Data.Set (Set)
+import qualified Data.Set as S
+import System.Directory (getModificationTime)
+
+import Hakyll.Core.Configuration
+import Hakyll.Core.Identifier
+import Hakyll.Core.ResourceProvider
+
+-- | A preview thread that periodically recompiles the site.
+--
+previewPoll :: HakyllConfiguration -- ^ Configuration
+ -> Set Resource -- ^ Resources to watch
+ -> IO () -- ^ Action called when something changes
+ -> IO () -- ^ Can block forever
+previewPoll _ resources callback = do
+ let files = map (toFilePath . unResource) $ S.toList resources
+ time <- getClockTime
+ loop files time
+ where
+ delay = 1000000
+ loop files time = do
+ threadDelay delay
+ modified <- any (time <) <$> mapM getModificationTime files
+ when modified callback
+ loop files =<< getClockTime