From 02ec8ea01254637facb30f77b7cb74be3b735c0d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 27 Jul 2012 15:33:24 -0400 Subject: much better webapp startup of the assistant This avoids forking another process, avoids polling, fixes a race, and avoids a rare forkProcess thread hang that I saw once time when starting the webapp. --- Utility/WebApp.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Utility') diff --git a/Utility/WebApp.hs b/Utility/WebApp.hs index 69864dc6d..75e8dde9e 100644 --- a/Utility/WebApp.hs +++ b/Utility/WebApp.hs @@ -32,6 +32,7 @@ import Blaze.ByteString.Builder.Char.Utf8 (fromText) import Blaze.ByteString.Builder (Builder) import Data.Monoid import Control.Arrow ((***)) +import Control.Concurrent localhost :: String localhost = "localhost" @@ -52,12 +53,12 @@ runBrowser url = boolSystem cmd [Param url] - - An IO action can also be run, to do something with the port number, - such as start a web browser to view the webapp. - -} + -} runWebApp :: Application -> (PortNumber -> IO ()) -> IO () runWebApp app observer = do sock <- localSocket + void $ forkIO $ runSettingsSocket defaultSettings sock app observer =<< socketPort sock - runSettingsSocket defaultSettings sock app {- Binds to a local socket, selecting any free port. - -- cgit v1.2.3