Skip to content

Commit

Permalink
return a result of lock callback.
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim committed Jun 9, 2017
1 parent 636505a commit 39aed7a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public function count(array $filter = [], array $options = [])
/**
* @param $id
* @param callable $lockCallback
*
* @return mixed
*/
public function lock($id, callable $lockCallback)
{
Expand All @@ -202,10 +204,13 @@ public function lock($id, callable $lockCallback)
}

$this->pessimisticLock->lock($id);
$result = null;
try {
if ($model = $this->findOne(['_id' => new ObjectID((string) $id)])) {
call_user_func($lockCallback, $model, $this);
$result = call_user_func($lockCallback, $model, $this);
}

return $result;
} finally {
$this->pessimisticLock->unlock($id);
}
Expand Down

0 comments on commit 39aed7a

Please sign in to comment.