Skip to content

Commit 833f7f4

Browse files
authored
Make Sendable protocols @preconcurrency (#1429)
Motivation: Protocols in the gRPC API predate `Sendable` but are required to be `Sendable` should be marked with `@preconcurrency`. Modifications: - Add `GRPCPreconcurrencySendable` - Make relevant protocols as `GRPCPreconcurrencySendable` rather than just `GRPCSendable`. Result: Better `Sendable` checking.
1 parent 7b68576 commit 833f7f4

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

Sources/GRPC/AsyncAwaitSupport/GRPCSendable.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@
1717
import NIOCore
1818

1919
#if compiler(>=5.6)
20-
@preconcurrency public typealias GRPCSendable = Swift.Sendable
20+
public typealias GRPCSendable = Swift.Sendable
2121
#else
2222
public typealias GRPCSendable = Any
2323
#endif // compiler(>=5.6)
2424

25+
#if compiler(>=5.6)
26+
@preconcurrency
27+
public protocol GRPCPreconcurrencySendable: Sendable {}
28+
#else
29+
public protocol GRPCPreconcurrencySendable {}
30+
#endif // compiler(>=5.6)
31+
2532
#if compiler(>=5.6)
2633
@preconcurrency public typealias GRPCChannelInitializer = @Sendable (Channel)
2734
-> EventLoopFuture<Void>

Sources/GRPC/ClientErrorDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Logging
2222
/// The intended use of this protocol is with `ClientConnection`. In order to avoid retain
2323
/// cycles, classes implementing this delegate **must not** maintain a strong reference to the
2424
/// `ClientConnection`.
25-
public protocol ClientErrorDelegate: AnyObject, GRPCSendable {
25+
public protocol ClientErrorDelegate: AnyObject, GRPCPreconcurrencySendable {
2626
/// Called when the client catches an error.
2727
///
2828
/// - Parameters:

Sources/GRPC/ConnectivityState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public enum ConnectivityState: GRPCSendable {
4747
case shutdown
4848
}
4949

50-
public protocol ConnectivityStateDelegate: AnyObject, GRPCSendable {
50+
public protocol ConnectivityStateDelegate: AnyObject, GRPCPreconcurrencySendable {
5151
/// Called when a change in `ConnectivityState` has occurred.
5252
///
5353
/// - Parameter oldState: The old connectivity state.

Sources/GRPC/GRPCChannel/GRPCChannel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import NIOCore
1717
import NIOHTTP2
1818
import SwiftProtobuf
1919

20-
public protocol GRPCChannel: GRPCSendable {
20+
public protocol GRPCChannel: GRPCPreconcurrencySendable {
2121
/// Makes a gRPC call on the channel with requests and responses conforming to
2222
/// `SwiftProtobuf.Message`.
2323
///

Sources/GRPC/GRPCClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import NIOHTTP2
1919
import SwiftProtobuf
2020

2121
/// A gRPC client.
22-
public protocol GRPCClient: GRPCSendable {
22+
public protocol GRPCClient: GRPCPreconcurrencySendable {
2323
/// The gRPC channel over which RPCs are sent and received. Note that this is distinct
2424
/// from `NIO.Channel`.
2525
var channel: GRPCChannel { get }

0 commit comments

Comments
 (0)