Skip to content

Commit

Permalink
refactor(Server.hs): move forkIO to outside of if-then-else
Browse files Browse the repository at this point in the history
  • Loading branch information
Vince committed Feb 23, 2024
1 parent b056b95 commit 7c663dd
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,21 @@ import Server.Monad
run :: Bool -> String -> IO Int
run devMode port = do
env <- initGlobalEnv
_threadId <- forkIO (printLog env)
if devMode
then do
_threadId <- forkIO (printLog env)
serve (Host "127.0.0.1") port $ \(sock, _remoteAddr) -> do
putStrLn $ "== connection established at " ++ port ++ " =="
handle <- socketToHandle sock ReadWriteMode
_ <- runServerWithHandles handle handle (serverDefn env)
putStrLn "== dev server closed =="
else do
_threadId <- forkIO (printLog env)
runServer (serverDefn env)
where
printLog :: GlobalEnv -> IO ()
printLog env = forever $ do
result <- readChan (globalChan env)
when devMode $ do
Text.putStrLn result
Text.putStrLn result

serverDefn :: GlobalEnv -> ServerDefinition ()
serverDefn env = ServerDefinition
Expand Down

0 comments on commit 7c663dd

Please sign in to comment.