8000 Acquires returns false instead of throwing exception · symfony/symfony-docs@4539a99 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 4539a99

Browse files
committed
Acquires returns false instead of throwing exception
1 parent cc06a7f commit 4539a99

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

components/lock.rst

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,25 @@ Then, you can use the :class:`Symfony\\Component\\Lock\\Factory` to create a
3030
Lock for your ``resource``.
3131

3232
The :method:`Symfony\\Component\\Lock\\LockInterface::acquire` method tries to
33-
acquire the lock. If the lock can not be acquired, the method throws a
34-
:class:`Symfony\\Component\\Lock\\Exception\\LockConflictedException`. You can
35-
safely call the ``acquire()`` method several times, even if you already acquired
36-
it.
33+
acquire the lock. If the lock can not be acquired, the method returns ``false``.
34+
You can safely call the ``acquire()`` method several times, even if you already
35+
acquired it.
3736

3837
.. code-block:: php
3938
4039
use Symfony\Component\Lock\Factory;
4140
use Symfony\Component\Lock\Store\SemaphoreStore;
42-
use Symfony\Component\Lock\Exception\LockConflictedException;
4341
4442
$store = new SemaphoreStore();
4543
$factory = new Factory($store);
4644
$lock = $factory->createLock('invoice-pdf-generation');
4745
48-
try {
49-
$lock->acquire();
46+
if ($lock->acquire()) {
5047
// the resource "invoice-pdf-generation" is locked.
5148
5249
// You can compute and generate invoice safely here.
5350
5451
$lock->release();
55-
} catch (LockConflictedException $e) {
56-
// the resource "invoice-pdf-generation" is already locked by another process
5752
}
5853
5954
The first argument of ``createLock`` is a string representation of the

0 commit comments

Comments
 (0)
0