on master help sign in
Client disconnecting does not take down example #271
commitfc2a2f6043759b97b68e129d03c61f56da54fded authorMichael Snoyman <michael@snoyman.com> dateWed 16 Jul 2014, 07:51 (12 years ago) parent2ec5fbb
1 file changed+2−2
wai-websockets/server.lhs+2−2
wai-websockets/server.lhs+2−2
@@ -13,7 +13,7 @@ nearby to check out the functions we use.
1313> import Data.Text (Text)
1414> import Control.Exception (fromException, handle)
1515> import Control.Monad (forM_, forever)
16−> import Control.Concurrent (MVar, newMVar, modifyMVar_, readMVar)
16+> import Control.Concurrent (MVar, newMVar, modifyMVar_, readMVar, forkIO)
1717> import Control.Monad.IO.Class (liftIO)
1818> import qualified Data.Text as T
1919> import qualified Data.Text.IO as T
@@ -66,7 +66,7 @@ Send a message to all clients, and log it on stdout.
6666> broadcast :: Text -> ServerState -> IO ()
6767> broadcast message clients = do
6868> T.putStrLn message
69−> forM_ clients $ \(_, conn) -> WS.sendTextData conn message
69+> forM_ clients $ \(_, conn) -> forkIO $ WS.sendTextData conn message
7070
7171The main function first creates a new state for the server, then spawns the
7272actual server. For this purpose, we use the simple server provided by