@@ -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