Skip to content

Commit 5233c2a

Browse files
jderussejaviereguiluz
authored andcommitted
Fix bad example of lock
1 parent a53de78 commit 5233c2a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

components/lock.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ method, the resource will stay locked until the timeout::
117117
// create an expiring lock that lasts 30 seconds
118118
$lock = $factory->createLock('charts-generation', 30);
119119

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

139-
$lock->acquire();
141+
if (!$lock->acquire()) {
142+
return;
143+
}
140144
try {
141145
while (!$finished) {
142146
// perform a small part of the job.
@@ -366,7 +370,9 @@ Using the above methods, a more robust code would be::
366370
// ...
367371
$lock = $factory->createLock('invoice-publication', 30);
368372

369-
$lock->acquire();
373+
if (!$lock->acquire()) {
374+
return;
375+
}
370376
while (!$finished) {
371377
if ($lock->getRemainingLifetime() <= 5) {
372378
if ($lock->isExpired()) {

0 commit comments

Comments
 (0)