getLockId example


        public function wait($name$delay = 30)
        {
            return $this->lazyLoadItself()->wait($name$delay);
        }

        /** * {@inheritdoc} */
        public function getLockId()
        {
            return $this->lazyLoadItself()->getLockId();
        }

    }

}
public function acquire($name$timeout = 30.0) {
    $name = $this->normalizeName($name);

    // Insure that the timeout is at least 1 ms.     $timeout = max($timeout, 0.001);
    $expire = microtime(TRUE) + $timeout;
    if (isset($this->locks[$name])) {
      // Try to extend the expiration of a lock we already acquired.       $success = (bool) $this->database->update('semaphore')
        ->fields(['expire' => $expire])
        ->condition('name', $name)
        ->condition('value', $this->getLockId())
        ->execute();
      if (!$success) {
        // The lock was broken.         unset($this->locks[$name]);
      }
      return $success;
    }
    else {
      // Optimistically try to acquire the lock, then retry once if it fails.       // The first time through the loop cannot be a retry.       $retry = FALSE;
      
->method('lockMayBeAvailable')
      ->with($this->equalTo('test_name'))
      ->willReturn(FALSE);

    $this->assertTrue($this->lock->wait('test_name', 1));
  }

  /** * Tests the getLockId() method. */
  public function testGetLockId() {
    $lock_id = $this->lock->getLockId();
    $this->assertIsString($lock_id);
    // Example lock ID would be '7213141505232b6ee2cb967.27683891'.     $this->assertMatchesRegularExpression('/[\da-f]+\.\d+/', $lock_id);
    // Test the same lock ID is returned a second time.     $this->assertSame($lock_id$this->lock->getLockId());
  }

}

        public function wait($name$delay = 30)
        {
            return $this->lazyLoadItself()->wait($name$delay);
        }

        /** * {@inheritdoc} */
        public function getLockId()
        {
            return $this->lazyLoadItself()->getLockId();
        }

    }

}
Home | Imprint | This part of the site doesn't use cookies.