diff --git a/Sources/SwiftGRPC/Core/Channel.swift b/Sources/SwiftGRPC/Core/Channel.swift index f0ca4c61f..b96fd1227 100644 --- a/Sources/SwiftGRPC/Core/Channel.swift +++ b/Sources/SwiftGRPC/Core/Channel.swift @@ -41,6 +41,7 @@ public class Channel { /// - Parameter address: the address of the server to be called /// - Parameter secure: if true, use TLS public init(address: String, secure: Bool = true) { + gRPC.initialize() host = address if secure { underlyingChannel = cgrpc_channel_create_secure(address, roots_pem(), nil) @@ -58,6 +59,7 @@ public class Channel { /// - Parameter certificates: a PEM representation of certificates to use /// - Parameter host: an optional hostname override public init(address: String, certificates: String, host: String?) { + gRPC.initialize() self.host = address underlyingChannel = cgrpc_channel_create_secure(address, certificates, host) completionQueue = CompletionQueue( diff --git a/Sources/SwiftGRPC/Runtime/ServiceClient.swift b/Sources/SwiftGRPC/Runtime/ServiceClient.swift index 3ced48acd..b06823b37 100644 --- a/Sources/SwiftGRPC/Runtime/ServiceClient.swift +++ b/Sources/SwiftGRPC/Runtime/ServiceClient.swift @@ -55,6 +55,13 @@ open class ServiceClientBase: ServiceClient { metadata = Metadata() } + /// Create a client using a pre-defined channel. + public init(channel: Channel) { + gRPC.initialize() + self.channel = channel + self.metadata = Metadata() + } + /// Create a client that makes secure connections with a custom certificate and (optional) hostname. public init(address: String, certificates: String, host: String?) { gRPC.initialize()