Browse Source

refactored completion queue setup into Call performOperations

Tim Burks 9 years ago
parent
commit
167f241bdb

+ 3 - 5
Packages/gRPC/Sources/Call.swift

@@ -149,15 +149,15 @@ public class Call {
   /// Initiate performance of a call without waiting for completion
   ///
   /// - Parameter operations: array of operations to be performed
-  /// - Parameter tag: integer tag that will be attached to these operations
+  /// - Parameter completionQueue: completion queue used to wait for completion
   /// - Returns: the result of initiating the call
   func performOperations(operations: OperationGroup,
-                         tag: Int64,
                          completionQueue: CompletionQueue)
     -> CallError {
+      completionQueue.operationGroups[operations.tag] = operations
       let mutex = CallLock.sharedInstance.mutex
       mutex.lock()
-      let error = cgrpc_call_perform(underlyingCall, operations.operations, tag)
+      let error = cgrpc_call_perform(underlyingCall, operations.operations, operations.tag)
       mutex.unlock()
       return CallError.callError(grpcCallError:error)
   }
@@ -209,9 +209,7 @@ public class Call {
 
   // perform a group of operations (used internally)
   private func perform(operations: OperationGroup) -> CallError {
-    self.completionQueue.operationGroups[operations.tag] = operations
     return performOperations(operations:operations,
-                             tag:operations.tag,
                              completionQueue: self.completionQueue)
   }
 

+ 2 - 0
Packages/gRPC/Sources/CompletionQueue.swift

@@ -111,6 +111,7 @@ internal class CompletionQueue {
             if event.success == 0 {
               print("something bad happened")
             } else {
+              // call the operation group completion handler
               operations.completion(event.success == 1)
             }
             self.operationGroups[tag] = nil
@@ -126,6 +127,7 @@ internal class CompletionQueue {
         }
       }
       DispatchQueue.main.async {
+        // call the queue completion handler
         completion()
       }
     }

+ 1 - 14
Packages/gRPC/Sources/Handler.swift

@@ -115,9 +115,7 @@ public class Handler {
         completion(nil)
       }
     }
-    self.completionQueue.operationGroups[operations.tag] = operations
     _ = call.performOperations(operations:operations,
-                               tag:operations.tag,
                                completionQueue: self.completionQueue)
   }
 
@@ -142,9 +140,7 @@ public class Handler {
     {(call_error) in
       self.shutdown()
     }
-    self.completionQueue.operationGroups[operations.tag] = operations
     _ = call.performOperations(operations:operations,
-                               tag:operations.tag,
                                completionQueue: self.completionQueue)
   }
 
@@ -165,9 +161,7 @@ public class Handler {
         completion()
       }
     }
-    self.completionQueue.operationGroups[operations.tag] = operations
     _ = call.performOperations(operations:operations,
-                               tag:operations.tag,
                                completionQueue: self.completionQueue)
   }
 
@@ -189,9 +183,8 @@ public class Handler {
         completion(nil)
       }
     }
-    self.completionQueue.operationGroups[operations.tag] = operations
+
     let call_error = call.performOperations(operations:operations,
-                                            tag:operations.tag,
                                             completionQueue: self.completionQueue)
     print("perform receiveMessage \(call_error)")
   }
@@ -208,9 +201,7 @@ public class Handler {
       print("server sendResponse complete")
       completion()
     }
-    self.completionQueue.operationGroups[operations.tag] = operations
     _ = call.performOperations(operations:operations,
-                               tag:operations.tag,
                                completionQueue: self.completionQueue)
   }
 
@@ -222,9 +213,7 @@ public class Handler {
       print("server receiveClose complete")
       completion()
     }
-    self.completionQueue.operationGroups[operations.tag] = operations
     let call_error = call.performOperations(operations:operations,
-                                            tag:operations.tag,
                                             completionQueue: self.completionQueue)
     print("perform receiveClose \(call_error)")
   }
@@ -240,9 +229,7 @@ public class Handler {
       print("server sendStatus complete")
       completion()
     }
-    self.completionQueue.operationGroups[operations.tag] = operations
     _ = call.performOperations(operations:operations,
-                               tag:operations.tag,
                                completionQueue: self.completionQueue)
   }
 }