on master help sign in
Run server in main thread
fdfbf3dSimonas Kazlauskas
src/Hakyll/Commands.hs+1−3
@@ -27,7 +27,6 @@ import Hakyll.Core.Util.File
27
27
28--------------------------------------------------------------------------------
28--------------------------------------------------------------------------------
29#ifdef PREVIEW_SERVER
29#ifdef PREVIEW_SERVER
30−import Control.Concurrent (forkIO)
31import qualified Data.Set as S
30import qualified Data.Set as S
32import Hakyll.Core.Identifier
31import Hakyll.Core.Identifier
33import Hakyll.Core.Rules.Internal
32import Hakyll.Core.Rules.Internal
@@ -68,9 +67,8 @@ clean conf = do
68preview :: Configuration -> Verbosity -> Rules a -> Int -> IO ()
67preview :: Configuration -> Verbosity -> Rules a -> Int -> IO ()
69#ifdef PREVIEW_SERVER
68#ifdef PREVIEW_SERVER
70preview conf verbosity rules port = do
69preview conf verbosity rules port = do
71− -- Run the server in a separate thread
72− _ <- forkIO $ server conf port
73 previewPoll conf update
70 previewPoll conf update
71+ server conf port
74 where
72 where
75 update = do
73 update = do
76 (exitCode, ruleSet) <- run conf verbosity rules
74 (exitCode, ruleSet) <- run conf verbosity rules
src/Hakyll/Preview/Poll.hs+3−9
@@ -3,12 +3,12 @@ module Hakyll.Preview.Poll
3 ) where
3 ) where
4
4
5--------------------------------------------------------------------------------
5--------------------------------------------------------------------------------
6−import Control.Concurrent (threadDelay)
7import Control.Monad (void)
6import Control.Monad (void)
8import Data.List (isPrefixOf)
7import Data.List (isPrefixOf)
9import Filesystem.Path.CurrentOS (decodeString, encodeString)
8import Filesystem.Path.CurrentOS (decodeString, encodeString)
10import System.Directory (canonicalizePath)
9import System.Directory (canonicalizePath)
11−import System.FSNotify (withManagerConf, watchTree, Event(..), WatchConfig(..))
10+import System.FSNotify (startManagerConf, watchTree,
11+ Event(..), WatchConfig(..))
12import System.IO.Error (catchIOError)
12import System.IO.Error (catchIOError)
13
13
14--------------------------------------------------------------------------------
14--------------------------------------------------------------------------------
@@ -21,7 +21,7 @@ import Hakyll.Core.Configuration
21previewPoll :: Configuration -- ^ Configuration
21previewPoll :: Configuration -- ^ Configuration
22 -> IO [FilePath] -- ^ Updating action
22 -> IO [FilePath] -- ^ Updating action
23 -> IO () -- ^ Can block forever
23 -> IO () -- ^ Can block forever
24−previewPoll conf update = withManagerConf (Debounce 0.1) monitor
24+previewPoll conf update = monitor =<< startManagerConf (Debounce 0.1)
25 where
25 where
26 path = decodeString $ providerDirectory conf
26 path = decodeString $ providerDirectory conf
27 monitor manager = do
27 monitor manager = do
@@ -29,7 +29,6 @@ previewPoll conf update = withManagerConf (Debounce 0.1) monitor
29 ignore <- mapM getPath
29 ignore <- mapM getPath
30 [destinationDirectory, storeDirectory, tmpDirectory]
30 [destinationDirectory, storeDirectory, tmpDirectory]
31 watchTree manager path (predicate ignore) (\_ -> void update)
31 watchTree manager path (predicate ignore) (\_ -> void update)
32− infiniteLoop
33 getPath fn = catchIOError (canonicalizePath $ fn conf)
32 getPath fn = catchIOError (canonicalizePath $ fn conf)
34 (const $ return $ fn conf)
33 (const $ return $ fn conf)
35 predicate ignore evt
34 predicate ignore evt
@@ -38,11 +37,6 @@ previewPoll conf update = withManagerConf (Debounce 0.1) monitor
38 | (ignoreFile conf) (eventPath evt) == True = False
37 | (ignoreFile conf) (eventPath evt) == True = False
39 | otherwise = True
38 | otherwise = True
40
39
41−infiniteLoop :: IO ()
42−infiniteLoop = do
43− threadDelay maxBound
44− infiniteLoop
45−
46eventPath :: Event -> FilePath
40eventPath :: Event -> FilePath
47eventPath (Added p _) = encodeString p
41eventPath (Added p _) = encodeString p
48eventPath (Modified p _) = encodeString p
42eventPath (Modified p _) = encodeString p