Skip to content

Commit

Permalink
[feature] finally return Closure added
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysice committed Oct 18, 2021
1 parent 6715a32 commit 48ca12a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ abstract protected function getCurrentOwner();

/**
* Attempt to acquire the lock
* @param null $callback
* @param null|\Closure $callback
* @param null|\Closure $finally
* @return bool|mixed
*/
public function get($callback = null)
public function get($callback = null, $finally = null)
{
$result = $this->acquire();
if($result && is_callable($callback)) {
Expand All @@ -68,6 +69,9 @@ public function get($callback = null)
$this->release();
}
}
if (!$result && is_callable($finally)) {
return $finally();
}

return $result;
}
Expand Down

0 comments on commit 48ca12a

Please sign in to comment.