on master help sign in
implement "withSocketM" using "finally"
commit3de89fe5dbf1491629ae1c966f97537f2b53ef49 authorHarendra Kumar <harendra.kumar@gmail.com> dateTue 8 Oct 2019, 11:12 (7 years ago) parentf8f323a
1 file changed+5−4
src/Streamly/Internal/Network/Socket.hs+5−4
src/Streamly/Internal/Network/Socket.hs+5−4
@@ -57,7 +57,7 @@ module Streamly.Internal.Network.Socket
5757where
5858
5959import Control.Concurrent (threadWaitWrite, rtsSupportsBoundThreads)
60−import Control.Monad.Catch (MonadCatch, onException)
60+import Control.Monad.Catch (MonadCatch, finally, MonadMask)
6161import Control.Monad.IO.Class (MonadIO(..))
6262import Control.Monad (when)
6363import Data.Word (Word8)
@@ -100,10 +100,11 @@ import qualified Streamly.Streams.StreamD.Type as D
100100--
101101-- @since 0.7.0
102102{-# INLINE withSocketM #-}
103−withSocketM :: (MonadCatch m, MonadIO m) => Socket -> (Socket -> m ()) -> m ()
103+withSocketM :: (MonadMask m, MonadIO m) => Socket -> (Socket -> m ()) -> m ()
104104withSocketM sk f = do
105− f sk `onException` liftIO (Net.close sk)
106− liftIO (Net.close sk)
105+-- f sk `onException` liftIO (Net.close sk)
106+-- liftIO (Net.close sk)
107+ finally (liftIO (Net.close sk)) (f sk)
107108
108109-- XXX bracket performs 2x better than 'finally'. That's perhaps because of
109110-- better fusion of "A.flattenArrays . readArrays"?