Skip to content
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

Mark unary async calls as @discardableResult. #399

Merged
merged 2 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 4 additions & 0 deletions Sources/Examples/Echo/Generated/echo.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ internal protocol Echo_EchoService: ServiceClient {
/// Synchronous. Unary.
func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata) throws -> Echo_EchoResponse
/// Asynchronous. Unary.
@discardableResult
func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall

/// Asynchronous. Server-streaming.
Expand All @@ -144,6 +145,7 @@ internal extension Echo_EchoService {
return try self.get(request, metadata: self.metadata)
}
/// Asynchronous. Unary.
@discardableResult
func get(_ request: Echo_EchoRequest, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
return try self.get(request, metadata: self.metadata, completion: completion)
}
Expand Down Expand Up @@ -172,6 +174,7 @@ internal final class Echo_EchoServiceClient: ServiceClientBase, Echo_EchoService
.run(request: request, metadata: customMetadata)
}
/// Asynchronous. Unary.
@discardableResult
internal func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
return try Echo_EchoGetCallBase(channel)
.start(request: request, metadata: customMetadata, completion: completion)
Expand Down Expand Up @@ -211,6 +214,7 @@ class Echo_EchoServiceTestStub: ServiceClientTestStubBase, Echo_EchoService {
defer { getResponses.removeFirst() }
return getResponses.first!
}
@discardableResult
func get(_ request: Echo_EchoRequest, metadata customMetadata: Metadata, completion: @escaping (Echo_EchoResponse?, CallResult) -> Void) throws -> Echo_EchoGetCall {
fatalError("not implemented")
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/protoc-gen-swiftgrpc/Generator-Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ extension Generator {
}
if asynchronousCode {
println("/// Asynchronous. Unary.")
println("@discardableResult")
Copy link
Collaborator

@MrMage MrMage Mar 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: whitespace? (also elsewhere)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I think I lost set noindent when swapping machines and the tap was only visible in the diff but not the implementation.

PTAL

println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName)")
}
case .serverStreaming:
Expand Down Expand Up @@ -217,6 +218,7 @@ extension Generator {
}
if asynchronousCode {
println("/// Asynchronous. Unary.")
println("@discardableResult")
println("func \(methodFunctionName)(_ request: \(methodInputName), completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {")
indent()
println("return try self.\(methodFunctionName)(request, metadata: self.metadata, completion: completion)")
Expand Down Expand Up @@ -272,6 +274,7 @@ extension Generator {
}
if asynchronousCode {
println("/// Asynchronous. Unary.")
println("@discardableResult")
println("\(access) func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {")
indent()
println("return try \(callName)Base(channel)")
Expand Down Expand Up @@ -340,6 +343,7 @@ extension Generator {
println("return \(methodFunctionName)Responses.first!")
outdent()
println("}")
println("@discardableResult")
println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName) {")
indent()
println("fatalError(\"not implemented\")")
Expand Down