Skip to content

Commit

Permalink
Only acquire the lock in Lock::get if a callback was not passed, ot…
Browse files Browse the repository at this point in the history
…herwise only check if it is available
  • Loading branch information
mattford committed Mar 6, 2024
1 parent c4e8cf5 commit 44cedf2
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Illuminate/Cache/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,14 @@ abstract protected function getCurrentOwner();
*/
public function get($callback = null)
{
$result = $this->acquire();

if ($result && is_callable($callback)) {
try {
// If a callable is passed, only check whether the lock is available.
if (is_callable($callback)) {
$owner = $this->getCurrentOwner();
if (empty($owner) || $owner === $this->owner()) {
return $callback();
} finally {
$this->release();
}
}

return $result;
return $this->acquire();
}

/**
Expand Down

0 comments on commit 44cedf2

Please sign in to comment.