on master help sign in
Merge pull request #230 from nagisa/watch-threading

Use OS threads for watch in Windows

commit677a7f0f2d6e2daeb57f7897b1f77b0993243839 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateWed 5 Mar 2014, 11:21 (13 years ago) parentecdc1d36521cd7
2 files changed+15−8
src/Hakyll/Commands.hs+14−7 web/tutorials/01-installation.markdown+1−1
src/Hakyll/Commands.hs+14−7
@@ -9,13 +9,15 @@ module Hakyll.Commands
99 , rebuild
1010 , server
1111 , deploy
12− , watch
12+ , watch
1313 ) where
1414
1515
1616--------------------------------------------------------------------------------
1717import System.Exit (exitWith, ExitCode)
18+import System.IO.Error (catchIOError)
1819import Control.Applicative
20+import Control.Monad (void)
1921import Control.Concurrent
2022
2123--------------------------------------------------------------------------------
@@ -83,17 +85,22 @@ preview _ _ _ _ = previewServerDisabled
8385watch :: Configuration -> Verbosity -> Int -> Bool -> Rules a -> IO ()
8486#ifdef WATCH_SERVER
8587watch conf verbosity port runServer rules = do
86− watchUpdates conf update
87− _ <- forkIO (server')
88− loop
88+#ifndef mingw32_HOST_OS
89+ _ <- forkIO $ watchUpdates conf update
90+#else
91+ -- Force windows users to compile with -threaded flag, as otherwise
92+ -- thread is blocked indefinitely.
93+ catchIOError (void $ forkOS $ watchUpdates conf update) $ do
94+ fail $ "Hakyll.Commands.watch: Could not start update watching " ++
95+ "thread. Did you compile with -threaded flag?"
96+#endif
97+ server'
8998 where
9099 update = do
91100 (_, ruleSet) <- run conf verbosity rules
92101 return $ rulesPattern ruleSet
93−
94102 loop = threadDelay 100000 >> loop
95−
96− server' = if runServer then server conf port else return ()
103+ server' = if runServer then server conf port else loop
97104#else
98105watch _ _ _ _ _ = watchServerDisabled
99106#endif
web/tutorials/01-installation.markdown+1−1
@@ -49,7 +49,7 @@ The file `site.hs` holds the configuration of your site, as an executable
4949haskell program. We can compile and run it like this:
5050
5151 $ cd my-site
52− $ ghc --make site.hs
52+ $ ghc --make -threaded site.hs
5353 $ ./site build
5454
5555If you installed `hakyll` with a preview server (this is the default), you can