Explorar o código

Merge pull request #81 from KyoheiG3/cancelable

Add Cancel to Call
Tim Burks %!s(int64=8) %!d(string=hai) anos
pai
achega
bc3ab540cb

+ 20 - 0
Examples/Echo/Generated/echo.client.pb.swift

@@ -81,6 +81,11 @@ internal class Echo_EchoGetCall {
       }
       return self
   }
+
+  /// Cancel the call.
+  internal func cancel() {
+    call.cancel()
+  }
 }
 
 /// Expand (Server Streaming)
@@ -140,6 +145,11 @@ internal class Echo_EchoExpandCall {
       }
     }
   }
+
+  /// Cancel the call.
+  internal func cancel() {
+    call.cancel()
+  }
 }
 
 /// Collect (Client Streaming)
@@ -202,6 +212,11 @@ internal class Echo_EchoCollectCall {
         throw error
       }
   }
+
+  /// Cancel the call.
+  internal func cancel() {
+    call.cancel()
+  }
 }
 
 /// Update (Bidirectional Streaming)
@@ -277,6 +292,11 @@ internal class Echo_EchoUpdateCall {
       completion()
     }
   }
+
+  /// Cancel the call.
+  internal func cancel() {
+    call.cancel()
+  }
 }
 
 /// Call methods of this class to make API calls.

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
Plugin/Sources/protoc-gen-swiftgrpc/templates.swift


+ 5 - 0
Plugin/Templates/client-call-bidistreaming.swift

@@ -71,4 +71,9 @@
       completion()
     }
   }
+
+  /// Cancel the call.
+  {{ access }} func cancel() {
+    call.cancel()
+  }
 }

+ 5 - 0
Plugin/Templates/client-call-clientstreaming.swift

@@ -58,4 +58,9 @@
         throw error
       }
   }
+
+  /// Cancel the call.
+  {{ access }} func cancel() {
+    call.cancel()
+  }
 }

+ 5 - 0
Plugin/Templates/client-call-serverstreaming.swift

@@ -55,4 +55,9 @@
       }
     }
   }
+
+  /// Cancel the call.
+  {{ access }} func cancel() {
+    call.cancel()
+  }
 }

+ 5 - 0
Plugin/Templates/client-call-unary.swift

@@ -46,4 +46,9 @@
       }
       return self
   }
+
+  /// Cancel the call.
+  {{ access }} func cancel() {
+    call.cancel()
+  }
 }

+ 1 - 0
Sources/CgRPC/include/CgRPC.h

@@ -157,6 +157,7 @@ const char *cgrpc_handler_call_peer(cgrpc_handler *h);
 // call support
 void cgrpc_call_destroy(cgrpc_call *call);
 grpc_call_error cgrpc_call_perform(cgrpc_call *call, cgrpc_operations *operations, int64_t tag);
+void cgrpc_call_cancel(cgrpc_call *call);
 
 // operations
 cgrpc_operations *cgrpc_operations_create();

+ 4 - 0
Sources/CgRPC/shim/call.c

@@ -33,3 +33,7 @@ grpc_call_error cgrpc_call_perform(cgrpc_call *call, cgrpc_operations *operation
                                                 NULL);
   return error;
 }
+
+void cgrpc_call_cancel(cgrpc_call *call) {
+  grpc_call_cancel(call->call, NULL);
+}

+ 8 - 0
Sources/gRPC/Call.swift

@@ -311,4 +311,12 @@ public class Call {
   public func messageQueueLength() -> Int {
     return messageQueue.count
   }
+
+  /// Finishes the request side of this call, notifies the server that the RPC should be cancelled,
+  /// and finishes the response side of the call with an error of code CANCELED.
+  public func cancel() {
+    Call.callMutex.lock()
+    cgrpc_call_cancel(underlyingCall)
+    Call.callMutex.unlock()
+  }
 }

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio