mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 02:11:53 +00:00
format all the things
This commit is contained in:
committed by
Keagan McClelland
parent
ac5acaa685
commit
e2d2fb6afc
@@ -1,14 +1,16 @@
|
||||
module DevelMain where
|
||||
|
||||
import Prelude
|
||||
import Application (getApplicationRepl, shutdownApp)
|
||||
import Prelude
|
||||
import Application ( getApplicationRepl
|
||||
, shutdownApp
|
||||
)
|
||||
|
||||
import Control.Monad ((>=>))
|
||||
import Control.Concurrent
|
||||
import Data.IORef
|
||||
import Foreign.Store
|
||||
import Network.Wai.Handler.Warp
|
||||
import GHC.Word
|
||||
import Control.Monad ( (>=>) )
|
||||
import Control.Concurrent
|
||||
import Data.IORef
|
||||
import Foreign.Store
|
||||
import Network.Wai.Handler.Warp
|
||||
import GHC.Word
|
||||
|
||||
|
||||
-- | Running your app inside GHCi.
|
||||
@@ -55,36 +57,35 @@ update = do
|
||||
mtidStore <- lookupStore tidStoreNum
|
||||
case mtidStore of
|
||||
-- no server running
|
||||
Nothing -> do
|
||||
done <- storeAction doneStore newEmptyMVar
|
||||
tid <- start done
|
||||
_ <- storeAction (Store tidStoreNum) (newIORef tid)
|
||||
return ()
|
||||
-- server is already running
|
||||
Just tidStore -> restartAppInNewThread tidStore
|
||||
where
|
||||
doneStore :: Store (MVar ())
|
||||
doneStore = Store 0
|
||||
Nothing -> do
|
||||
done <- storeAction doneStore newEmptyMVar
|
||||
tid <- start done
|
||||
_ <- storeAction (Store tidStoreNum) (newIORef tid)
|
||||
return ()
|
||||
-- server is already running
|
||||
Just tidStore -> restartAppInNewThread tidStore
|
||||
where
|
||||
doneStore :: Store (MVar ())
|
||||
doneStore = Store 0
|
||||
|
||||
-- shut the server down with killThread and wait for the done signal
|
||||
restartAppInNewThread :: Store (IORef ThreadId) -> IO ()
|
||||
restartAppInNewThread tidStore = modifyStoredIORef tidStore $ \tid -> do
|
||||
killThread tid
|
||||
withStore doneStore takeMVar
|
||||
readStore doneStore >>= start
|
||||
-- shut the server down with killThread and wait for the done signal
|
||||
restartAppInNewThread :: Store (IORef ThreadId) -> IO ()
|
||||
restartAppInNewThread tidStore = modifyStoredIORef tidStore $ \tid -> do
|
||||
killThread tid
|
||||
withStore doneStore takeMVar
|
||||
readStore doneStore >>= start
|
||||
|
||||
|
||||
-- | Start the server in a separate thread.
|
||||
start :: MVar () -- ^ Written to when the thread is killed.
|
||||
-> IO ThreadId
|
||||
start done = do
|
||||
(port, site, app) <- getApplicationRepl
|
||||
forkFinally
|
||||
(runSettings (setPort port defaultSettings) app)
|
||||
-- Note that this implies concurrency
|
||||
-- between shutdownApp and the next app that is starting.
|
||||
-- Normally this should be fine
|
||||
(\_ -> putMVar done () >> shutdownApp site)
|
||||
-- | Start the server in a separate thread.
|
||||
start :: MVar () -- ^ Written to when the thread is killed.
|
||||
-> IO ThreadId
|
||||
start done = do
|
||||
(port, site, app) <- getApplicationRepl
|
||||
forkFinally (runSettings (setPort port defaultSettings) app)
|
||||
-- Note that this implies concurrency
|
||||
-- between shutdownApp and the next app that is starting.
|
||||
-- Normally this should be fine
|
||||
(\_ -> putMVar done () >> shutdownApp site)
|
||||
|
||||
-- | kill the server
|
||||
shutdown :: IO ()
|
||||
@@ -92,10 +93,10 @@ shutdown = do
|
||||
mtidStore <- lookupStore tidStoreNum
|
||||
case mtidStore of
|
||||
-- no server running
|
||||
Nothing -> putStrLn "no Yesod app running"
|
||||
Just tidStore -> do
|
||||
withStore tidStore $ readIORef >=> killThread
|
||||
putStrLn "Yesod app is shutdown"
|
||||
Nothing -> putStrLn "no Yesod app running"
|
||||
Just tidStore -> do
|
||||
withStore tidStore $ readIORef >=> killThread
|
||||
putStrLn "Yesod app is shutdown"
|
||||
|
||||
tidStoreNum :: Word32
|
||||
tidStoreNum = 1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{-# LANGUAGE PackageImports #-}
|
||||
import "start9-registry" Application (develMain)
|
||||
import Prelude (IO)
|
||||
import "start9-registry" Application ( develMain )
|
||||
import Prelude ( IO )
|
||||
|
||||
main :: IO ()
|
||||
main = develMain
|
||||
main = develMain
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Application (appMain)
|
||||
import Application ( appMain )
|
||||
import Startlude
|
||||
|
||||
main :: IO ()
|
||||
|
||||
Reference in New Issue
Block a user