claude-memory/graph/code-patterns/optional-locking-parameter-pattern-for-read-vs-write-command-88bbf5.md
Cal Corum b140d4d82a migrate: 313 memories from MemoryGraph
- 313 new markdown files created
- 30 relationships embedded
- 313 entries indexed
- State initialized with usage data
2026-02-13 11:11:48 -06:00

1.3 KiB

id type title tags importance confidence created updated relations
88bbf5f1-2d76-4e68-9c62-ca72e464f5c0 code_pattern Optional locking parameter pattern for read vs write commands
paper-dynasty
python
discord-bot
architecture
locking
concurrency
pattern
0.75 0.8 2026-02-04T15:53:57.725265+00:00 2026-02-04T15:53:57.725265+00:00
target type direction strength
5d8e1ff5-3354-4cfa-ab63-bf96b5ce1e01 BUILDS_ON incoming 0.5

In Paper Dynasty, added lock_play parameter (default=True) to checks_log_interaction() to distinguish read-only commands from write commands. Read-only commands like /show-card and /settings-ingame use lock_play=False to avoid unnecessary locking. Write commands that modify play state use default lock_play=True. This reduces lock contention and prevents blocking users during non-critical operations. Pattern: Create single validation function with optional locking, rather than duplicating validation logic for read vs write. Also moved actual state modifications to callbacks (dropdown selections) where lock is acquired at last possible moment, keeping commands themselves lock-free. Structure: Command shows UI -> User interaction triggers callback -> Callback acquires lock -> Modifies state -> Releases lock. This minimizes lock hold time.