Skip to content

Commit

Permalink
add getter for identifier and allow disabling of auto lock break on d…
Browse files Browse the repository at this point in the history
…estruct
  • Loading branch information
matthi4s committed May 5, 2021
1 parent 50a6968 commit 3d77f63
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/EtcdLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ public static function setDelayPerUnavailableRetry(int $delayPerRetry)
*/
protected $retries = 0;

/**
* Automatically try to break the lock on destruct if possible
*
* @var bool
*/
protected $breakOnDestruct = true;

/**
* Create a lock
*
Expand Down Expand Up @@ -295,6 +302,26 @@ public function isLocked()
return false;
}

/**
* Get the used identifier for this lock
*
* @return string
*/
public function getIdentifier(): ?string
{
return $this->identifier;
}

/**
* Dis/enable automatic lock break on object destruct
*
* @param bool $breakOnDestruct
*/
public function setBreakOnDestruct(bool $breakOnDestruct): void
{
$this->breakOnDestruct = $breakOnDestruct;
}

/**
* Refresh the lock
*
Expand Down Expand Up @@ -559,7 +586,7 @@ protected function updateFromString($lockString)
*/
public function __destruct()
{
if ($this->isLocked()) {
if ($this->breakOnDestruct && $this->isLocked()) {
$this->break();
}
}
Expand Down

0 comments on commit 3d77f63

Please sign in to comment.