Skip to content

Commit

Permalink
Move Call also into .Call
Browse files Browse the repository at this point in the history
This should have been part of #199.
  • Loading branch information
edsko committed Jul 24, 2024
1 parent 4a04a91 commit 379fc0b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
30 changes: 19 additions & 11 deletions src/Network/GRPC/Client/Call.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
-- Intended for unqualified import.
module Network.GRPC.Client.Call (
-- * Construction
withRPC
Call -- opaque
, withRPC

-- * Open (ongoing) call
, sendInput
Expand Down Expand Up @@ -46,7 +47,7 @@ import Data.Text qualified as Text
import Data.Version
import GHC.Stack

import Network.GRPC.Client.Connection (Connection, ConnParams, Call(..))
import Network.GRPC.Client.Connection (Connection, ConnParams(..))
import Network.GRPC.Client.Connection qualified as Connection
import Network.GRPC.Client.Session
import Network.GRPC.Common
Expand All @@ -64,6 +65,13 @@ import Paths_grapesy qualified as Grapesy
Open a call
-------------------------------------------------------------------------------}

-- | State of the call
--
-- This type is kept abstract (opaque) in the public facing API.
data Call rpc = SupportsClientRpc rpc => Call {
callChannel :: Session.Channel (ClientSession rpc)
}

-- | Scoped RPC call
--
-- Typical usage:
Expand All @@ -72,7 +80,7 @@ import Paths_grapesy qualified as Grapesy
-- > .. use 'call' to send and receive messages
--
-- for some previously established connection 'conn'
-- (see 'Network.GRPC.Client.withConnection') and where @ListFeatures@ is some
-- (see 'Network.GRPC.Client.withConnection) and where @ListFeatures@ is some
-- kind of RPC.
--
-- The call is setup in the background, and might not yet have been established
Expand Down Expand Up @@ -197,7 +205,7 @@ startRPC conn _ callParams = do

channel <-
Session.setupRequestChannel
callSession
session
connToServer
serverClosedConnection
flowStart
Expand Down Expand Up @@ -225,7 +233,7 @@ startRPC conn _ callParams = do
_mAlreadyClosed <- Session.close channel exitReason
return ()

return $ Call callSession channel
return $ Call channel
where
connParams :: ConnParams
connParams = Connection.connParams conn
Expand All @@ -235,16 +243,16 @@ startRPC conn _ callParams = do
requestTimeout =
asum [
callTimeout callParams
, Connection.connDefaultTimeout connParams
, connDefaultTimeout connParams
]
, requestMetadata =
customMetadataMapFromList metadata
, requestCompression =
compressionId <$> cOut
, requestAcceptCompression = Just $
Compression.offer $ Connection.connCompression connParams
Compression.offer $ connCompression connParams
, requestContentType =
Connection.connContentType connParams
connContentType connParams
, requestMessageType =
Just MessageTypeDefault
, requestUserAgent = Just $
Expand All @@ -264,9 +272,9 @@ startRPC conn _ callParams = do
()
}

callSession :: ClientSession rpc
callSession = ClientSession {
clientCompression = Connection.connCompression connParams
session :: ClientSession rpc
session = ClientSession {
clientCompression = connCompression connParams
, clientUpdateMeta = Connection.updateConnectionMeta conn
}

Expand Down
10 changes: 0 additions & 10 deletions src/Network/GRPC/Client/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
module Network.GRPC.Client.Connection (
-- * Definition
Connection -- opaque
, Call(..)
, withConnection
-- * Configuration
, Server(..)
Expand Down Expand Up @@ -41,7 +40,6 @@ import System.Random

import Network.GRPC.Client.Meta (Meta)
import Network.GRPC.Client.Meta qualified as Meta
import Network.GRPC.Client.Session
import Network.GRPC.Common.Compression qualified as Compr
import Network.GRPC.Common.HTTP2Settings
import Network.GRPC.Spec
Expand Down Expand Up @@ -81,14 +79,6 @@ data Connection = Connection {
, connStateVar :: TVar ConnectionState
}

-- | State of the call
--
-- This type is kept abstract (opaque) in the public facing API.
data Call rpc = SupportsClientRpc rpc => Call {
callSession :: ClientSession rpc
, callChannel :: Session.Channel (ClientSession rpc)
}

{-------------------------------------------------------------------------------
Config
-------------------------------------------------------------------------------}
Expand Down

0 comments on commit 379fc0b

Please sign in to comment.