Skip to content

Commit 57b7a59

Browse files
authored
Merge branch 'main' into gb-uuid-extraction
2 parents c0209df + a6e9057 commit 57b7a59

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed

Sources/Examples/HelloWorld/Client/main.swift renamed to Sources/Examples/HelloWorld/Client/HelloWorldClient.swift

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import NIOCore
2121
import NIOPosix
2222

2323
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
24+
@main
2425
struct HelloWorld: AsyncParsableCommand {
2526
@Option(help: "The port to connect to")
2627
var port: Int = 1234
@@ -67,4 +68,11 @@ struct HelloWorld: AsyncParsableCommand {
6768
}
6869
}
6970
}
71+
#else
72+
@main
73+
enum HelloWorld {
74+
static func main() {
75+
fatalError("This example requires swift >= 5.6")
76+
}
77+
}
7078
#endif // compiler(>=5.6)

Sources/Examples/HelloWorld/Server/main.swift renamed to Sources/Examples/HelloWorld/Server/HelloWorldServer.swift

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import NIOCore
2121
import NIOPosix
2222

2323
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
24+
@main
2425
struct HelloWorld: AsyncParsableCommand {
2526
@Option(help: "The port to listen on for new connections")
2627
var port = 1234
@@ -43,4 +44,11 @@ struct HelloWorld: AsyncParsableCommand {
4344
try await server.onClose.get()
4445
}
4546
}
47+
#else
48+
@main
49+
enum HelloWorld {
50+
static func main() {
51+
fatalError("This example requires swift >= 5.6")
52+
}
53+
}
4654
#endif // compiler(>=5.6)

Sources/GRPC/ClientConnection.swift

+44-2
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,15 @@ extension ClientConnection {
454454
/// used to add additional handlers to the pipeline and is intended for debugging.
455455
///
456456
/// - Warning: The initializer closure may be invoked *multiple times*.
457-
public var debugChannelInitializer: GRPCChannelInitializer?
457+
#if compiler(>=5.6)
458+
@preconcurrency
459+
public var debugChannelInitializer: (@Sendable (Channel) -> EventLoopFuture<Void>)?
460+
#else
461+
public var debugChannelInitializer: ((Channel) -> EventLoopFuture<Void>)?
462+
#endif
458463

459464
#if canImport(NIOSSL)
465+
#if compiler(>=5.6)
460466
/// Create a `Configuration` with some pre-defined defaults. Prefer using
461467
/// `ClientConnection.secure(group:)` to build a connection secured with TLS or
462468
/// `ClientConnection.insecure(group:)` to build a plaintext connection.
@@ -480,6 +486,7 @@ extension ClientConnection {
480486
/// - Parameter debugChannelInitializer: A channel initializer will be called after gRPC has
481487
/// initialized the channel. Defaults to `nil`.
482488
@available(*, deprecated, renamed: "default(target:eventLoopGroup:)")
489+
@preconcurrency
483490
public init(
484491
target: ConnectionTarget,
485492
eventLoopGroup: EventLoopGroup,
@@ -496,7 +503,7 @@ extension ClientConnection {
496503
label: "io.grpc",
497504
factory: { _ in SwiftLogNoOpLogHandler() }
498505
),
499-
debugChannelInitializer: GRPCChannelInitializer? = nil
506+
debugChannelInitializer: (@Sendable (Channel) -> EventLoopFuture<Void>)? = nil
500507
) {
501508
self.target = target
502509
self.eventLoopGroup = eventLoopGroup
@@ -512,6 +519,41 @@ extension ClientConnection {
512519
self.backgroundActivityLogger = backgroundActivityLogger
513520
self.debugChannelInitializer = debugChannelInitializer
514521
}
522+
#else
523+
@available(*, deprecated, renamed: "default(target:eventLoopGroup:)")
524+
public init(
525+
target: ConnectionTarget,
526+
eventLoopGroup: EventLoopGroup,
527+
errorDelegate: ClientErrorDelegate? = LoggingClientErrorDelegate(),
528+
connectivityStateDelegate: ConnectivityStateDelegate? = nil,
529+
connectivityStateDelegateQueue: DispatchQueue? = nil,
530+
tls: Configuration.TLS? = nil,
531+
connectionBackoff: ConnectionBackoff? = ConnectionBackoff(),
532+
connectionKeepalive: ClientConnectionKeepalive = ClientConnectionKeepalive(),
533+
connectionIdleTimeout: TimeAmount = .minutes(30),
534+
callStartBehavior: CallStartBehavior = .waitsForConnectivity,
535+
httpTargetWindowSize: Int = 8 * 1024 * 1024,
536+
backgroundActivityLogger: Logger = Logger(
537+
label: "io.grpc",
538+
factory: { _ in SwiftLogNoOpLogHandler() }
539+
),
540+
debugChannelInitializer: ((Channel) -> EventLoopFuture<Void>)? = nil
541+
) {
542+
self.target = target
543+
self.eventLoopGroup = eventLoopGroup
544+
self.errorDelegate = errorDelegate
545+
self.connectivityStateDelegate = connectivityStateDelegate
546+
self.connectivityStateDelegateQueue = connectivityStateDelegateQueue
547+
self.tlsConfiguration = tls.map { GRPCTLSConfiguration(transforming: $0) }
548+
self.connectionBackoff = connectionBackoff
549+
self.connectionKeepalive = connectionKeepalive
550+
self.connectionIdleTimeout = connectionIdleTimeout
551+
self.callStartBehavior = callStartBehavior
552+
self.httpTargetWindowSize = httpTargetWindowSize
553+
self.backgroundActivityLogger = backgroundActivityLogger
554+
self.debugChannelInitializer = debugChannelInitializer
555+
}
556+
#endif // compiler(>=5.6)
515557
#endif // canImport(NIOSSL)
516558

517559
private init(eventLoopGroup: EventLoopGroup, target: ConnectionTarget) {

Sources/GRPC/ConnectionPool/GRPCChannelPool.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ extension GRPCChannelPool {
167167
/// This may be used to add additional handlers to the pipeline and is intended for debugging.
168168
///
169169
/// - Warning: The initializer closure may be invoked *multiple times*.
170-
public var debugChannelInitializer: GRPCChannelInitializer?
170+
#if compiler(>=5.6)
171+
@preconcurrency
172+
public var debugChannelInitializer: (@Sendable (Channel) -> EventLoopFuture<Void>)?
173+
#else
174+
public var debugChannelInitializer: ((Channel) -> EventLoopFuture<Void>)?
175+
#endif
171176

172177
/// An error delegate which is called when errors are caught.
173178
public var errorDelegate: ClientErrorDelegate?

Sources/GRPC/GRPCChannel/GRPCChannelBuilder.swift

+12-1
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,24 @@ extension ClientConnection.Builder {
315315
/// used to add additional handlers to the pipeline and is intended for debugging.
316316
///
317317
/// - Warning: The initializer closure may be invoked *multiple times*.
318+
#if compiler(>=5.6)
318319
@discardableResult
320+
@preconcurrency
319321
public func withDebugChannelInitializer(
320-
_ debugChannelInitializer: @escaping GRPCChannelInitializer
322+
_ debugChannelInitializer: @Sendable @escaping (Channel) -> EventLoopFuture<Void>
321323
) -> Self {
322324
self.configuration.debugChannelInitializer = debugChannelInitializer
323325
return self
324326
}
327+
#else
328+
@discardableResult
329+
public func withDebugChannelInitializer(
330+
_ debugChannelInitializer: @escaping (Channel) -> EventLoopFuture<Void>
331+
) -> Self {
332+
self.configuration.debugChannelInitializer = debugChannelInitializer
333+
return self
334+
}
335+
#endif
325336
}
326337

327338
extension Double {

0 commit comments

Comments
 (0)