Browse Source

Move the code that executes a transaction block to a separate method.

Daniele Alessandri 14 years ago
parent
commit
d01e738d59
1 changed files with 23 additions and 19 deletions
  1. 23 19
      lib/Predis/Transaction/MultiExecContext.php

+ 23 - 19
lib/Predis/Transaction/MultiExecContext.php

@@ -190,26 +190,8 @@ class MultiExecContext {
         $attemptsLeft = isset($this->_options['retry']) ? (int)$this->_options['retry'] : 0;
 
         do {
-            $blockException = null;
             if ($block !== null) {
-                $this->flagState(self::STATE_INSIDEBLOCK);
-                try {
-                    $block($this);
-                }
-                catch (CommunicationException $exception) {
-                    $blockException = $exception;
-                }
-                catch (ServerException $exception) {
-                    $blockException = $exception;
-                }
-                catch (\Exception $exception) {
-                    $blockException = $exception;
-                    $this->discard();
-                }
-                $this->unflagState(self::STATE_INSIDEBLOCK);
-                if ($blockException !== null) {
-                    throw $blockException;
-                }
+                $this->executeTransactionBlock($block);
             }
 
             if (count($this->_commands) === 0) {
@@ -252,6 +234,28 @@ class MultiExecContext {
         return $returnValues;
     }
 
+    private function executeTransactionBlock($block) {
+        $blockException = null;
+        $this->flagState(self::STATE_INSIDEBLOCK);
+        try {
+            $block($this);
+        }
+        catch (CommunicationException $exception) {
+            $blockException = $exception;
+        }
+        catch (ServerException $exception) {
+            $blockException = $exception;
+        }
+        catch (\Exception $exception) {
+            $blockException = $exception;
+            $this->discard();
+        }
+        $this->unflagState(self::STATE_INSIDEBLOCK);
+        if ($blockException !== null) {
+            throw $blockException;
+        }
+    }
+
     private function onProtocolError($message) {
         // Since a MULTI/EXEC block cannot be initialized over a clustered
         // connection, we can safely assume that Predis\Client::getConnection()