File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,33 @@ method can be safely called repeatedly, even if the lock is already acquired.
7373 across several requests. To disable the automatic release behavior, set the
7474 third argument of the ``createLock() `` method to ``false ``.
7575
76+ Serializing Locks
77+ ------------------
78+
79+ The ``Key `` contains the state of the ``Lock`` and can be serialized. This
80+ allows the user to begin a long job in a process by acquiring the lock, and
81+ to continue the job in an other process within the same lock.::
82+
83+ use Symfony\Component\Lock\Key;
84+ use Symfony\Component\Lock\Lock;
85+
86+ $key = new Key('article.'.$article->getId());
87+ $lock = new Lock($key, $this->store, 300, false);
88+ $lock->acquire(true);
89+
90+ $this->bus->dispatch(new RefreshTaxonomy($article, $key));
91+
92+ .. note::
93+
94+ Don't forget to disable the autoRelease to avoid releasing the lock when
95+ the destructor will be called.
96+
97+ All stores are not compatible with serialization and cross-process locking:
98+ For instance the kernel will automatically releases Semaphores acquires by the
99+ :ref:`SemaphoreStore <lock-store-semaphore>` store.
100+ Wen a lock is acquired with such store, and hte application try to serialize
101+ the key, and exception will be thrown
102+
76103.. _lock-blocking-locks:
77104
78105Blocking Locks
You can’t perform that action at this time.
0 commit comments