Skip to content

Commit f10a8ec

Browse files
authored
Merge pull request #202 from rebello95/channel-specification
Support for Channel specification on ServiceClient
2 parents 5ebf7a3 + bb6bd07 commit f10a8ec

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Sources/SwiftGRPC/Core/Channel.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class Channel {
4141
/// - Parameter address: the address of the server to be called
4242
/// - Parameter secure: if true, use TLS
4343
public init(address: String, secure: Bool = true) {
44+
gRPC.initialize()
4445
host = address
4546
if secure {
4647
underlyingChannel = cgrpc_channel_create_secure(address, roots_pem(), nil)
@@ -58,6 +59,7 @@ public class Channel {
5859
/// - Parameter certificates: a PEM representation of certificates to use
5960
/// - Parameter host: an optional hostname override
6061
public init(address: String, certificates: String, host: String?) {
62+
gRPC.initialize()
6163
self.host = address
6264
underlyingChannel = cgrpc_channel_create_secure(address, certificates, host)
6365
completionQueue = CompletionQueue(

Sources/SwiftGRPC/Runtime/ServiceClient.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ open class ServiceClientBase: ServiceClient {
5555
metadata = Metadata()
5656
}
5757

58+
/// Create a client using a pre-defined channel.
59+
public init(channel: Channel) {
60+
gRPC.initialize()
61+
self.channel = channel
62+
self.metadata = Metadata()
63+
}
64+
5865
/// Create a client that makes secure connections with a custom certificate and (optional) hostname.
5966
public init(address: String, certificates: String, host: String?) {
6067
gRPC.initialize()

0 commit comments

Comments
 (0)