File tree 1 file changed +4
-9
lines changed
Filter options
1 file changed +4
-9
lines changed
Original file line number Diff line number Diff line change @@ -30,30 +30,25 @@ Then, you can use the :class:`Symfony\\Component\\Lock\\Factory` to create a
30
30
Lock for your ``resource ``.
31
31
32
32
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.
37
36
38
37
.. code-block :: php
39
38
40
39
use Symfony\Component\Lock\Factory;
41
40
use Symfony\Component\Lock\Store\SemaphoreStore;
42
- use Symfony\Component\Lock\Exception\LockConflictedException;
43
41
44
42
$store = new SemaphoreStore();
45
43
$factory = new Factory($store);
46
44
$lock = $factory->createLock('invoice-pdf-generation');
47
45
48
- try {
49
- $lock->acquire();
46
+ if ($lock->acquire()) {
50
47
// the resource "invoice-pdf-generation" is locked.
51
48
52
49
// You can compute and generate invoice safely here.
53
50
54
51
$lock->release();
55
- } catch (LockConflictedException $e) {
56
- // the resource "invoice-pdf-generation" is already locked by another process
57
52
}
58
53
59
54
The first argument of ``createLock `` is a string representation of the
You can’t perform that action at this time.
0 commit comments