fix: enhance MessageBus by added lock and extractions. - #875
fix: enhance MessageBus by added lock and extractions.#875StarsExpress wants to merge 4 commits into
Conversation
Refactored emit() and provide_response() as well.
b6f72a9 to
53c4c81
Compare
|
Locks make me very nervous. |
Haha I hear you — locks are usually where bugs go to hide. Plus, we all like freedom a lot 😅 This morning I ran some commands, and have these interesting but also tricky results: 1. Command tracing
2. PyCharm's
|


Refs issue #438's 3rd point to adjust
code_puppy/messaging/bus.py: MessageBus.Part 1: add a lock for
provide_response()Originally,
emit()has withself._lock:wrapping the code to addmessageintoself._outgoing.However,
provide_response()didn't have it, so I let it have one as well — for wrapping the code to addcommandintoself._incoming.Part 2: refactor
emit()andprovide_response()A shared static method joins
MessageBusnow:How
emit()calls_put_item_into_queue:self._put_item_into_queue(self._outgoing, message)How
provide_responsecalls_put_item_into_queue:self._put_item_into_queue(self._incoming, command)Part 3:
TypeVar("T")shared at module levelSince several methods need
TypeVar("T")for type safety, the following definition moves to a place between imports and the start ofMessageBus:T = TypeVar("T") # Auto-detect variable type.