Skip to content

Commit a6e9057

Browse files
authored
Fix sendable warnings (#1513)
Motivation: Warnings were emitted for `debugChannelInitializer`s as they were not `Sendable` even though their definition via a typealias was. Modifications: Expand out typealiases and add appropriate `@Sendable` and `@preconcurrency` annotations. Results: No warnings.
1 parent 0332b34 commit a6e9057

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

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)