Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4539a99

Browse filesBrowse files
committed
Acquires returns false instead of throwing exception
1 parent cc06a7f commit 4539a99
Copy full SHA for 4539a99

File tree

1 file changed

+4
-9
lines changed
Filter options

1 file changed

+4
-9
lines changed

‎components/lock.rst

Copy file name to clipboardExpand all lines: components/lock.rst
+4-9Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.