on master help sign in
Simplify the type of `globalManager`
b312babMark Karpov
Network/HTTP/Req.hs+4−4
@@ -585,10 +585,10 @@ req' method url body options m = do
585 withReqManager (m request)
585 withReqManager (m request)
586
586
587-- | Perform an action using the global implicit 'L.Manager' that the rest
587-- | Perform an action using the global implicit 'L.Manager' that the rest
588−-- of the library uses. This allows to reuse connections that the
588+-- of the library uses. This allows us to reuse connections that the
589-- 'L.Manager' controls.
589-- 'L.Manager' controls.
590withReqManager :: (MonadIO m) => (L.Manager -> m a) -> m a
590withReqManager :: (MonadIO m) => (L.Manager -> m a) -> m a
591−withReqManager m = liftIO (readIORef globalManager) >>= m
591+withReqManager m = m globalManager
592
592
593-- | The global 'L.Manager' that 'req' uses. Here we just go with the
593-- | The global 'L.Manager' that 'req' uses. Here we just go with the
594-- default settings, so users don't need to deal with this manager stuff at
594-- default settings, so users don't need to deal with this manager stuff at
@@ -601,7 +601,7 @@ withReqManager m = liftIO (readIORef globalManager) >>= m
601-- manager. From that moment on the 'IORef' will be just reused—exactly the
601-- manager. From that moment on the 'IORef' will be just reused—exactly the
602-- behavior we want here in order to maximize connection sharing. GHC could
602-- behavior we want here in order to maximize connection sharing. GHC could
603-- spoil the plan by inlining the definition, hence the @NOINLINE@ pragma.
603-- spoil the plan by inlining the definition, hence the @NOINLINE@ pragma.
604−globalManager :: IORef L.Manager
604+globalManager :: L.Manager
605globalManager = unsafePerformIO $ do
605globalManager = unsafePerformIO $ do
606 context <- NC.initConnectionContext
606 context <- NC.initConnectionContext
607 let settings =
607 let settings =
@@ -610,7 +610,7 @@ globalManager = unsafePerformIO $ do
610 def
610 def
611 Nothing
611 Nothing
612 manager <- L.newManager settings
612 manager <- L.newManager settings
613− newIORef manager
613+ return manager
614{-# NOINLINE globalManager #-}
614{-# NOINLINE globalManager #-}
615
615
616----------------------------------------------------------------------------
616----------------------------------------------------------------------------