Skip to content

Commit 4dc7c1b

Browse files
committed
Fix bad example of lock
1 parent e9c6102 commit 4dc7c1b

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
@@ -118,7 +118,9 @@ method, the resource will stay locked until the timeout::
118118
// create an expiring lock that lasts 30 seconds
119119
$lock = $factory->createLock('charts-generation', 30);
120120

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

140-
$lock->acquire();
142+
if (!$lock->acquire()) {
143+
return;
144+
}
141145
try {
142146
while (!$finished) {
143147
// perform a small part of the job.
@@ -455,7 +459,9 @@ Using the above methods, a more robust code would be::
455459
// ...
456460
$lock = $factory->createLock('invoice-publication', 30);
457461

458-
$lock->acquire();
462+
if (!$lock->acquire()) {
463+
return;
464+
}
459465
while (!$finished) {
460466
if ($lock->getRemainingLifetime() <= 5) {
461467
if ($lock->isExpired()) {

0 commit comments

Comments
 (0)