From 4df9b9c240219fc01bf9ee8f15a6a2ee80d2233b Mon Sep 17 00:00:00 2001 From: joe Date: Tue, 14 Nov 2017 18:09:08 -0500 Subject: Minor stylistic changes. --- Presence/Server.hs | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'Presence') diff --git a/Presence/Server.hs b/Presence/Server.hs index f82a93c5..1e46c051 100644 --- a/Presence/Server.hs +++ b/Presence/Server.hs @@ -6,6 +6,7 @@ {-# LANGUAGE RankNTypes #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TupleSections #-} +{-# LANGUAGE LambdaCase #-} ----------------------------------------------------------------------------- -- | -- Module : Server @@ -313,15 +314,13 @@ server allocate = do (post <=< flip connWrite bs . cstate) $ Map.lookup con map - doit server (Connect addr params) = do - mb <- atomically $ do - rmap <- readTVar (retrymap server) - return $ Map.lookup addr rmap - maybe forkit - (\(v,d) -> do b <- atomically $ readTVar v - interruptDelay d - when (not b) forkit) - mb + doit server (Connect addr params) = join $ atomically $ do + Map.lookup addr <$> readTVar (retrymap server) + >>= return . \case + Nothing -> forkit + Just (v,d) -> do b <- atomically $ readTVar v + interruptDelay d + when (not b) forkit where forkit = void . forkIO $ do proto <- getProtocolNumber "tcp" @@ -347,17 +346,14 @@ server allocate = do resultVar <- atomically newEmptyTMVar timer <- interruptibleDelay (retryVar,action) <- atomically $ do - let noop = return () map <- readTVar (retrymap server) - let mb = Map.lookup addr map - action <- - maybe (return noop) - (\(v,d) -> do writeTVar v False - return $ interruptDelay d) - mb + action <- case Map.lookup addr map of + Nothing -> return $ return () + Just (v,d) -> do writeTVar v False + return $ interruptDelay d v <- newTVar True - writeTVar (retrymap server) (Map.insert addr (v,timer) map) - return (v,action) + writeTVar (retrymap server) $! Map.insert addr (v,timer) map + return (v,action :: IO ()) action fix $ \retryLoop -> do utc <- getCurrentTime -- cgit v1.2.3