wrapped everything in the EnvM Monad, the logging might commence

This commit is contained in:
Dennis Frieberg 2021-04-05 22:11:07 +02:00
parent 27a51c2121
commit ac303abcc0
7 changed files with 78 additions and 51 deletions

View file

@ -8,12 +8,12 @@ module Main where
-- We need some way too configure things, like the port we run on.
-- see Network.Wai.Handler.Warp.Settings and Network.Wai.Handler.Warp.runSettings
import Control.Concurrent.MVar
import qualified Network.Wai as Wai
import WaiApp
import Control.Concurrent
import UnliftIO.Concurrent
import Backend.Backend
import Options.Applicative
import Environment
-- maybe we should use Control.Concurrent.ParallelIO but right
-- now we just rely that the backends fork and don't block
@ -21,15 +21,17 @@ main :: IO ()
main = do
options <- execParser commandLineParser
serverState <- newMVar newServerState
let backs = zipWith (runBackend $ waiApplication serverState) options backends
waitFor' <- sequence backs
let waitFor = concat waitFor'
blockBackends waitFor
runEnvM defaultEnv $ do
waiApp <- waiApplication serverState
let backs = zipWith (runBackend waiApp) options backends
waitFor' <- sequence backs
let waitFor = concat waitFor'
blockBackends waitFor
blockBackends :: [MVar ()] -> IO ()
blockBackends :: [MVar ()] -> EnvM ()
blockBackends = mapM_ takeMVar
runBackend :: Wai.Application -> Either (Maybe String) Bool -> Backend -> IO [MVar ()]
runBackend :: Wai.Application -> Either (Maybe String) Bool -> Backend -> EnvM [MVar ()]
runBackend app (Left (Just conf)) (BackendWithConfig b _ _) = b app conf
runBackend _ (Left Nothing) (BackendWithConfig _ _ _) = return []
runBackend app (Right True) (BackendWithoutConfig b _ _) = b app