summaryrefslogtreecommitdiff
path: root/src/Hakyll
diff options
context:
space:
mode:
authorSimonas Kazlauskas <git@kazlauskas.me>2013-03-30 17:24:20 +0200
committerSimonas Kazlauskas <git@kazlauskas.me>2013-03-30 17:48:36 +0200
commitfdfbf3dd344318dbb4f104644c6b952e48df294c (patch)
tree3ef901cd17ed5ae84db20cbb9e63236d51074a35 /src/Hakyll
parent42cdd649db36d6be52d297be36bedfc1f3ba8ee7 (diff)
downloadhakyll-fdfbf3dd344318dbb4f104644c6b952e48df294c.tar.gz
Run server in main thread
Diffstat (limited to 'src/Hakyll')
-rw-r--r--src/Hakyll/Commands.hs4
-rw-r--r--src/Hakyll/Preview/Poll.hs12
2 files changed, 4 insertions, 12 deletions
diff --git a/src/Hakyll/Commands.hs b/src/Hakyll/Commands.hs
index 6e0b9f2..140e0d9 100644
--- a/src/Hakyll/Commands.hs
+++ b/src/Hakyll/Commands.hs
@@ -27,7 +27,6 @@ import Hakyll.Core.Util.File
--------------------------------------------------------------------------------
#ifdef PREVIEW_SERVER
-import Control.Concurrent (forkIO)
import qualified Data.Set as S
import Hakyll.Core.Identifier
import Hakyll.Core.Rules.Internal
@@ -68,9 +67,8 @@ clean conf = do
preview :: Configuration -> Verbosity -> Rules a -> Int -> IO ()
#ifdef PREVIEW_SERVER
preview conf verbosity rules port = do
- -- Run the server in a separate thread
- _ <- forkIO $ server conf port
previewPoll conf update
+ server conf port
where
update = do
(exitCode, ruleSet) <- run conf verbosity rules
diff --git a/src/Hakyll/Preview/Poll.hs b/src/Hakyll/Preview/Poll.hs
index c6c9b9a..e9920ad 100644
--- a/src/Hakyll/Preview/Poll.hs
+++ b/src/Hakyll/Preview/Poll.hs
@@ -3,12 +3,12 @@ module Hakyll.Preview.Poll
) where
--------------------------------------------------------------------------------
-import Control.Concurrent (threadDelay)
import Control.Monad (void)
import Data.List (isPrefixOf)
import Filesystem.Path.CurrentOS (decodeString, encodeString)
import System.Directory (canonicalizePath)
-import System.FSNotify (withManagerConf, watchTree, Event(..), WatchConfig(..))
+import System.FSNotify (startManagerConf, watchTree,
+ Event(..), WatchConfig(..))
import System.IO.Error (catchIOError)
--------------------------------------------------------------------------------
@@ -21,7 +21,7 @@ import Hakyll.Core.Configuration
previewPoll :: Configuration -- ^ Configuration
-> IO [FilePath] -- ^ Updating action
-> IO () -- ^ Can block forever
-previewPoll conf update = withManagerConf (Debounce 0.1) monitor
+previewPoll conf update = monitor =<< startManagerConf (Debounce 0.1)
where
path = decodeString $ providerDirectory conf
monitor manager = do
@@ -29,7 +29,6 @@ previewPoll conf update = withManagerConf (Debounce 0.1) monitor
ignore <- mapM getPath
[destinationDirectory, storeDirectory, tmpDirectory]
watchTree manager path (predicate ignore) (\_ -> void update)
- infiniteLoop
getPath fn = catchIOError (canonicalizePath $ fn conf)
(const $ return $ fn conf)
predicate ignore evt
@@ -38,11 +37,6 @@ previewPoll conf update = withManagerConf (Debounce 0.1) monitor
| (ignoreFile conf) (eventPath evt) == True = False
| otherwise = True
-infiniteLoop :: IO ()
-infiniteLoop = do
- threadDelay maxBound
- infiniteLoop
-
eventPath :: Event -> FilePath
eventPath (Added p _) = encodeString p
eventPath (Modified p _) = encodeString p