public function synchronized(callable $code)
    {
        return $this->loop->execute(function () use ($code) {
            try {
                // BEGIN
                $this->pdo->beginTransaction();
            } catch (\PDOException $e) {
                throw new LockAcquireException("Could not begin transaction.", 0, $e);
            }
            
            try {
                // Unit of work
                $result = $code();
                $this->pdo->commit();
                $this->loop->end();
                return $result;
            } catch (\Exception $e) {
                $this->rollBack($e);
                
                if (self::hasPDOException($e)) {
                    return; // Replay
                } else {
                    throw $e;
                }
            }
        });
    }
public function synchronized(callable $code)
    {
        return $this->loop->execute(function () use ($code) {
            try {
                // BEGIN
                $this->pdo->beginTransaction();
            } catch (\PDOException $e) {
                throw new LockAcquireException("Could not begin transaction.", 0, $e);
            }
            
            try {
                // Unit of work
                $result = $code();
                $this->pdo->commit();
                $this->loop->end();
                return $result;
            } catch (\Exception $e) {
                $this->rollBack($e);
                
                if (self::hasPDOException($e)) {
                    return; // Replay
                } else {
                    throw $e;
                }
            }
        });
    }
public function synchronized ( callable $ code ) { return $ this -> loop -> execute ( function ( ) use ( $ code ) { try { // BEGIN $ this -> pdo -> beginTransaction ( ) ; } catch ( \ PDOException $ e ) { throw new LockAcquireException ( "Could not begin transaction." , 0 , $ e ) ; } try { // Unit of work $ result = $ code ( ) ; $ this -> pdo -> commit ( ) ; $ this -> loop -> end ( ) ; return $ result ; } catch ( \ Exception $ e ) { $ this -> rollBack ( $ e ) ; if ( self :: hasPDOException ( $ e ) ) { return ; // Replay } else { throw $ e ; } } } ) ; }
Executes the critical code within a transaction.

It's up to the user to set the correct transaction isolation level.
However if the transaction fails, the code will be executed again in a
new transaction. Therefore the code must not have any side effects
besides SQL statements. Also the isolation level should be conserved for
the repeated transaction.

A transaction is considered as failed if a PDOException or an exception
which has a PDOException as any previous exception was raised.

If the code throws any other exception, the transaction is rolled back
and won't  be replayed.

@param callable $code The synchronized execution block.
@return mixed The return value of the execution block.
@SuppressWarnings(PHPMD)

@throws \Exception The execution block threw an exception.
@throws LockAcquireException The transaction was not commited.
Executes the critical code within a transaction .