How to end the race_ function?
I want to finish race_
, but I don't know how to do it.
This is the code I have right now:
mainLoop :: Handle -> String -> IO ()
mainLoop handle username = do
_ <- race_ fromServer toServer
putStrLn "Race is done"
return ()
where
fromServer = forever $ do
line <- hGetLine handle
putStrLn $ "Server: " ++ line
toServer = do
line <- getLine
case line of
":quit" -> do
--hPutStrLn handle "blabla"
return ()
_ -> do
hPutStrLn handle $ line
toServer
If I uncomment the line hPutStrLn handle "blabla"
, the user sees Race is done
when he types :quit
. Without this line, the program just hangs when the user types :quit
.
I find it wrong to use hPutStrLn handle "blabla"
only for completion race_
. I guess there is a better function for completing a function race_
. Any idea?
It seems strange to me that the simple one return ()
doesn't work, since both hPutStrLn
and return
return an empty IO action.
The full context can be found here . The handle is being created handle <- connectTo "localhost" (PortNumber 4000)
. The server is created in server.hs . I am running this code on Windows 7 in "Git bash" (msysgit) with runhaskell
.
source to share