summaryrefslogtreecommitdiff
path: root/src-interval
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-23 10:11:55 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-23 10:11:55 +0100
commit5abc3d87e234c2f92b6c5481200d1f813ca2ce6f (patch)
tree422fd79a23bb2af298ccf223c8a3b9709426044a /src-interval
parent371c28cb1a7976740f104b0737b6b9c37c08b72f (diff)
downloadhakyll-5abc3d87e234c2f92b6c5481200d1f813ca2ce6f.tar.gz
Add cabal flag for inotify
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