Skip to content

Commit 59b0839

Browse files
committed
Add missing 'Sendable' conformance
Motivation: Sendable conformance was missing in a handful of places which generates warnings in newer toolchains. Modifications: - Make client calls Sendable - Client call wrappers should require Sendable types (this was implicitly enfored by calls requiring request and response types to be Sendable). This also requires the async sequence of requests to be Sendable for calls where requests are streamed which required a codegen change. - Make the various gRPC async sequence types conditionally Sendable Result: Fewer warnings
1 parent 65f7bee commit 59b0839

17 files changed

+123
-74
lines changed

Sources/Examples/Echo/Model/echo.grpc.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ extension Echo_EchoAsyncClientProtocol {
316316
public func collect<RequestStream>(
317317
_ requests: RequestStream,
318318
callOptions: CallOptions? = nil
319-
) async throws -> Echo_EchoResponse where RequestStream: AsyncSequence, RequestStream.Element == Echo_EchoRequest {
319+
) async throws -> Echo_EchoResponse where RequestStream: AsyncSequence & Sendable, RequestStream.Element == Echo_EchoRequest {
320320
return try await self.performAsyncClientStreamingCall(
321321
path: Echo_EchoClientMetadata.Methods.collect.path,
322322
requests: requests,
@@ -340,7 +340,7 @@ extension Echo_EchoAsyncClientProtocol {
340340
public func update<RequestStream>(
341341
_ requests: RequestStream,
342342
callOptions: CallOptions? = nil
343-
) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: AsyncSequence, RequestStream.Element == Echo_EchoRequest {
343+
) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: AsyncSequence & Sendable, RequestStream.Element == Echo_EchoRequest {
344344
return self.performAsyncBidirectionalStreamingCall(
345345
path: Echo_EchoClientMetadata.Methods.update.path,
346346
requests: requests,

Sources/Examples/RouteGuide/Model/route_guide.grpc.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ extension Routeguide_RouteGuideAsyncClientProtocol {
335335
public func recordRoute<RequestStream>(
336336
_ requests: RequestStream,
337337
callOptions: CallOptions? = nil
338-
) async throws -> Routeguide_RouteSummary where RequestStream: AsyncSequence, RequestStream.Element == Routeguide_Point {
338+
) async throws -> Routeguide_RouteSummary where RequestStream: AsyncSequence & Sendable, RequestStream.Element == Routeguide_Point {
339339
return try await self.performAsyncClientStreamingCall(
340340
path: Routeguide_RouteGuideClientMetadata.Methods.recordRoute.path,
341341
requests: requests,
@@ -359,7 +359,7 @@ extension Routeguide_RouteGuideAsyncClientProtocol {
359359
public func routeChat<RequestStream>(
360360
_ requests: RequestStream,
361361
callOptions: CallOptions? = nil
362-
) -> GRPCAsyncResponseStream<Routeguide_RouteNote> where RequestStream: AsyncSequence, RequestStream.Element == Routeguide_RouteNote {
362+
) -> GRPCAsyncResponseStream<Routeguide_RouteNote> where RequestStream: AsyncSequence & Sendable, RequestStream.Element == Routeguide_RouteNote {
363363
return self.performAsyncBidirectionalStreamingCall(
364364
path: Routeguide_RouteGuideClientMetadata.Methods.routeChat.path,
365365
requests: requests,

Sources/GRPC/AsyncAwaitSupport/AsyncWriter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ internal final actor AsyncWriter<Delegate: AsyncWriterDelegate>: Sendable {
5757
typealias PendingEnd = _Pending<End>
5858

5959
@usableFromInline
60-
internal enum _CompletionState {
60+
internal enum _CompletionState: Sendable {
6161
/// Finish hasn't been called yet. May move to `pending` or `completed`.
6262
case incomplete
6363
/// Finish has been called but the writer is paused. May move to `completed`.

Sources/GRPC/AsyncAwaitSupport/GRPCAsyncBidirectionalStreamingCall.swift

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

2020
/// Async-await variant of BidirectionalStreamingCall.
2121
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
22-
public struct GRPCAsyncBidirectionalStreamingCall<Request: Sendable, Response: Sendable> {
22+
public struct GRPCAsyncBidirectionalStreamingCall<Request: Sendable, Response: Sendable>: Sendable {
2323
private let call: Call<Request, Response>
2424
private let responseParts: StreamingResponseParts<Response>
2525
private let responseSource: PassthroughMessageSource<Response, Error>

Sources/GRPC/AsyncAwaitSupport/GRPCAsyncClientStreamingCall.swift

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

2020
/// Async-await variant of `ClientStreamingCall`.
2121
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
22-
public struct GRPCAsyncClientStreamingCall<Request: Sendable, Response: Sendable> {
22+
public struct GRPCAsyncClientStreamingCall<Request: Sendable, Response: Sendable>: Sendable {
2323
private let call: Call<Request, Response>
2424
private let responseParts: UnaryResponseParts<Response>
2525

Sources/GRPC/AsyncAwaitSupport/GRPCAsyncRequestStream.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,9 @@ public struct GRPCAsyncRequestStream<Element: Sendable>: AsyncSequence {
5252
}
5353
}
5454

55+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
56+
extension GRPCAsyncRequestStream: Sendable where Element: Sendable {}
57+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
58+
extension GRPCAsyncRequestStream.Iterator: Sendable where Element: Sendable {}
59+
5560
#endif

Sources/GRPC/AsyncAwaitSupport/GRPCAsyncRequestStreamWriter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/// try await stream.finish()
3232
/// ```
3333
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
34-
public struct GRPCAsyncRequestStreamWriter<Request: Sendable> {
34+
public struct GRPCAsyncRequestStreamWriter<Request: Sendable>: Sendable {
3535
@usableFromInline
3636
internal let asyncWriter: AsyncWriter<Delegate<Request>>
3737

Sources/GRPC/AsyncAwaitSupport/GRPCAsyncResponseStream.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ public struct GRPCAsyncResponseStream<Element>: AsyncSequence {
4949
}
5050
}
5151

52+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
53+
extension GRPCAsyncResponseStream: Sendable where Element: Sendable {}
54+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
55+
extension GRPCAsyncResponseStream.Iterator: Sendable where Element: Sendable {}
56+
5257
#endif

Sources/GRPC/AsyncAwaitSupport/GRPCAsyncResponseStreamWriter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
/// Writer for server-streaming RPC handlers to provide responses.
2020
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
21-
public struct GRPCAsyncResponseStreamWriter<Response: Sendable> {
21+
public struct GRPCAsyncResponseStreamWriter<Response: Sendable>: Sendable {
2222
@usableFromInline
2323
internal typealias Element = (Response, Compression)
2424

Sources/GRPC/AsyncAwaitSupport/GRPCAsyncUnaryCall.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import NIOHPACK
2222
/// Note: while this object is a `struct`, its implementation delegates to `Call`. It therefore
2323
/// has reference semantics.
2424
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
25-
public struct GRPCAsyncUnaryCall<Request: Sendable, Response: Sendable> {
25+
public struct GRPCAsyncUnaryCall<Request: Sendable, Response: Sendable>: Sendable {
2626
private let call: Call<Request, Response>
2727
private let responseParts: UnaryResponseParts<Response>
2828

0 commit comments

Comments
 (0)