Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add public API to create connection IDs #1737

Merged
merged 1 commit into from
Dec 8, 2023
Merged
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
26 changes: 23 additions & 3 deletions Sources/GRPC/ConnectionPool/GRPCChannelPool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import Logging
import NIOCore
import NIOPosix

import struct Foundation.UUID

public enum GRPCChannelPool {
/// Make a new ``GRPCChannel`` on which calls may be made to gRPC services.
///
Expand Down Expand Up @@ -290,14 +292,32 @@ extension GRPCChannelPool.Configuration {

/// The ID of a connection in the connection pool.
public struct GRPCConnectionID: Hashable, Sendable, CustomStringConvertible {
private let id: ConnectionManagerID
private enum Value: Sendable, Hashable {
case managerID(ConnectionManagerID)
case uuid(UUID)
}

private let id: Value

public var description: String {
return String(describing: self.id)
switch self.id {
case .managerID(let id):
return String(describing: id)
case .uuid(let uuid):
return String(describing: uuid)
}
}

internal init(_ id: ConnectionManagerID) {
self.id = id
self.id = .managerID(id)
}

/// Create a new unique connection ID.
///
/// Normally you don't have to create connection IDs, gRPC will create them on your behalf.
/// However creating them manually is useful when testing the ``GRPCConnectionPoolDelegate``.
public init() {
self.id = .uuid(UUID())
}
}

Expand Down