SimpleEventIsolation
extends BaseEventIsolation
in package
A mutex-backed event isolation strategy that serialises concurrent updates sharing the same `StorageKey`.
Ported from aiogram.fsm.storage.memory.SimpleEventIsolation
(aiogram/fsm/storage/memory.py:85-97). The upstream implementation holds a
defaultdict of asyncio.Lock instances keyed by StorageKey. The PHP port
uses Amp\Sync\LocalKeyedMutex, which already manages per-key lock instances
internally, so no _locks dict is needed here.
Key derivation: the storage key string is built by joining all StorageKey
fields with a colon separator. This mirrors the full-fidelity key used by
DefaultKeyBuilder(withBotId=true, withBusinessConnectionId=true, withDestiny=true).
close() behaviour: upstream clears its defaultdict to release all in-memory
lock objects. LocalKeyedMutex does not expose a clear() method; resetting the
instance to a fresh LocalKeyedMutex achieves the same effect — any pending
acquires on the old mutex will still complete, and future acquires use the new
(empty) instance.
Table of Contents
Properties
- $mutex : LocalKeyedMutex
Methods
- __construct() : mixed
- close() : void
- Resets the internal mutex to a fresh instance, releasing all tracked per-key lock objects.
- lock() : Lock
- Acquires a per-key mutex lock for `$key`.
- buildKey() : string
- Derives a stable string key from all `StorageKey` fields.
Properties
$mutex
private
LocalKeyedMutex
$mutex
Methods
__construct()
public
__construct() : mixed
close()
Resets the internal mutex to a fresh instance, releasing all tracked per-key lock objects.
public
close() : void
Mirrors upstream's SimpleEventIsolation.close() which clears the
internal _locks defaultdict (memory.py:97).
lock()
Acquires a per-key mutex lock for `$key`.
public
lock(StorageKey $key) : Lock
Blocks (suspends the current fiber) until the lock is available.
The returned Lock wraps the underlying Amp\Sync\Lock; call
release() in a finally block to free the mutex.
Parameters
- $key : StorageKey
-
Storage address to lock.
Return values
LockbuildKey()
Derives a stable string key from all `StorageKey` fields.
private
buildKey(StorageKey $key) : string
Format: <botId>:<chatId>:<threadId|"">:<userId>:<businessConnectionId|"">:<destiny>
Parameters
- $key : StorageKey