diff --git a/components/lock.rst b/components/lock.rst index 19f1d2dbf8b..fdaf3b7686a 100644 --- a/components/lock.rst +++ b/components/lock.rst @@ -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 { @@ -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. @@ -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()) {