Skip to content

[async-await] Code generation for "simple, but safe" wrapper client calls. #1261

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

Merged
merged 18 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
69 changes: 69 additions & 0 deletions Sources/Examples/Echo/Model/echo.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,75 @@ extension Echo_EchoAsyncClientProtocol {
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
extension Echo_EchoAsyncClientProtocol {
public func get(
_ request: Echo_EchoRequest,
callOptions: CallOptions? = nil
) async throws -> Echo_EchoResponse {
return try await self.performAsyncUnaryCall(
path: "/echo.Echo/Get",
request: request,
callOptions: callOptions ?? self.defaultCallOptions
)
}

public func expand(
_ request: Echo_EchoRequest,
callOptions: CallOptions? = nil
) -> GRPCAsyncResponseStream<Echo_EchoResponse> {
return self.performAsyncServerStreamingCall(
path: "/echo.Echo/Expand",
request: request,
callOptions: callOptions ?? self.defaultCallOptions
)
}

public func collect<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) async throws -> Echo_EchoResponse where RequestStream: Sequence, RequestStream.Element == Echo_EchoRequest {
return try await self.performAsyncClientStreamingCall(
path: "/echo.Echo/Collect",
requests: requests,
callOptions: callOptions ?? self.defaultCallOptions
)
}

public func collect<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) async throws -> Echo_EchoResponse where RequestStream: AsyncSequence, RequestStream.Element == Echo_EchoRequest {
return try await self.performAsyncClientStreamingCall(
path: "/echo.Echo/Collect",
requests: requests,
callOptions: callOptions ?? self.defaultCallOptions
)
}

public func update<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: Sequence, RequestStream.Element == Echo_EchoRequest {
return self.performAsyncBidirectionalStreamingCall(
path: "/echo.Echo/Update",
requests: requests,
callOptions: callOptions ?? self.defaultCallOptions
)
}

public func update<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) -> GRPCAsyncResponseStream<Echo_EchoResponse> where RequestStream: AsyncSequence, RequestStream.Element == Echo_EchoRequest {
return self.performAsyncBidirectionalStreamingCall(
path: "/echo.Echo/Update",
requests: requests,
callOptions: callOptions ?? self.defaultCallOptions
)
}
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public struct Echo_EchoAsyncClient: Echo_EchoAsyncClientProtocol {
public var channel: GRPCChannel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension GRPCChannel {
/// - request: The request to send.
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncUnaryCall<Request: Message, Response: Message>(
internal func makeAsyncUnaryCall<Request: Message, Response: Message>(
path: String,
request: Request,
callOptions: CallOptions,
Expand All @@ -50,7 +50,7 @@ extension GRPCChannel {
/// - request: The request to send.
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncUnaryCall<Request: GRPCPayload, Response: GRPCPayload>(
internal func makeAsyncUnaryCall<Request: GRPCPayload, Response: GRPCPayload>(
path: String,
request: Request,
callOptions: CallOptions,
Expand All @@ -73,7 +73,7 @@ extension GRPCChannel {
/// - path: Path of the RPC, e.g. "/echo.Echo/Get"
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncClientStreamingCall<Request: Message, Response: Message>(
internal func makeAsyncClientStreamingCall<Request: Message, Response: Message>(
path: String,
callOptions: CallOptions,
interceptors: [ClientInterceptor<Request, Response>] = []
Expand All @@ -94,7 +94,7 @@ extension GRPCChannel {
/// - path: Path of the RPC, e.g. "/echo.Echo/Get"
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncClientStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
internal func makeAsyncClientStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
path: String,
callOptions: CallOptions,
interceptors: [ClientInterceptor<Request, Response>] = []
Expand All @@ -116,7 +116,7 @@ extension GRPCChannel {
/// - request: The request to send.
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncServerStreamingCall<Request: Message, Response: Message>(
internal func makeAsyncServerStreamingCall<Request: Message, Response: Message>(
path: String,
request: Request,
callOptions: CallOptions,
Expand All @@ -140,7 +140,7 @@ extension GRPCChannel {
/// - request: The request to send.
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncServerStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
internal func makeAsyncServerStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
path: String,
request: Request,
callOptions: CallOptions,
Expand All @@ -163,7 +163,7 @@ extension GRPCChannel {
/// - path: Path of the RPC, e.g. "/echo.Echo/Get"
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncBidirectionalStreamingCall<Request: Message, Response: Message>(
internal func makeAsyncBidirectionalStreamingCall<Request: Message, Response: Message>(
path: String,
callOptions: CallOptions,
interceptors: [ClientInterceptor<Request, Response>] = []
Expand All @@ -184,7 +184,7 @@ extension GRPCChannel {
/// - path: Path of the RPC, e.g. "/echo.Echo/Get"
/// - callOptions: Options for the RPC.
/// - interceptors: A list of interceptors to intercept the request and response stream with.
public func makeAsyncBidirectionalStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
internal func makeAsyncBidirectionalStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
path: String,
callOptions: CallOptions,
interceptors: [ClientInterceptor<Request, Response>] = []
Expand Down
Loading