Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/SwiftGRPC/Core/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions Sources/SwiftGRPC/Runtime/ServiceClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ open class ServiceClientBase: ServiceClient {
metadata = Metadata()
}

/// Create a client using a pre-defined channel.
public init(channel: Channel) {
gRPC.initialize()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this gRPC.initialize() call, given that this is now done by Channel.init. Also in the other constructors above and below.

Also, I'd suggest moving this constructor below or above all the other ones?

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()
Expand Down