浏览代码

Mark unary async calls as @discardableResult. (#399)

* Mark unary async calls as @discardableResult.

The result is only necessary if you need cancellation.

* Fix indents.
Martin Petrov 6 年之前
父节点
当前提交
f7807da0de

+ 4 - 0
Sources/Examples/Echo/Generated/echo.grpc.swift

@@ -123,6 +123,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.
@@ -148,6 +149,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)
   }
@@ -176,6 +178,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)
@@ -215,6 +218,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")
   }

+ 4 - 0
Sources/protoc-gen-swiftgrpc/Generator-Client.swift

@@ -183,6 +183,7 @@ extension Generator {
         }
         if asynchronousCode {
           println("/// Asynchronous. Unary.")
+          println("@discardableResult")
           println("func \(methodFunctionName)(_ request: \(methodInputName), metadata customMetadata: Metadata, completion: @escaping (\(methodOutputName)?, CallResult) -> Void) throws -> \(callName)")
         }
       case .serverStreaming:
@@ -225,6 +226,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)")
@@ -280,6 +282,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)")
@@ -348,6 +351,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\")")