Skip to content

Fix bad example of lock #14179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions components/lock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ method, the resource will stay locked until the timeout::
// create an expiring lock that lasts 30 seconds
$lock = $factory->createLock('charts-generation', 30);

$lock->acquire();
if (!$lock->acquire()) {
return;
}
try {
// perform a job during less than 30 seconds
} finally {
Expand All @@ -136,7 +138,9 @@ to reset the TTL to its original value::
// ...
$lock = $factory->createLock('charts-generation', 30);

$lock->acquire();
if (!$lock->acquire()) {
return;
}
try {
while (!$finished) {
// perform a small part of the job.
Expand Down Expand Up @@ -366,7 +370,9 @@ Using the above methods, a more robust code would be::
// ...
$lock = $factory->createLock('invoice-publication', 30);

$lock->acquire();
if (!$lock->acquire()) {
return;
}
while (!$finished) {
if ($lock->getRemainingLifetime() <= 5) {
if ($lock->isExpired()) {
Expand Down