forked from p15670423/monkey
Common: Use IslandEventTopic enum's names for pypubsub topics
This commit is contained in:
parent
1a09f26fd9
commit
004337583a
|
@ -14,13 +14,13 @@ class PyPubSubIslandEventQueue(IIslandEventQueue):
|
|||
self._refs = []
|
||||
|
||||
def subscribe(self, topic: IslandEventTopic, subscriber: IslandEventSubscriber):
|
||||
topic_value = topic.value # needs to be a string for pypubsub
|
||||
topic_name = topic.name # needs to be a string for pypubsub
|
||||
try:
|
||||
subscriber_name = subscriber.__name__
|
||||
except AttributeError:
|
||||
subscriber_name = subscriber.__class__.__name__
|
||||
|
||||
logging.debug(f"Subscriber {subscriber_name} subscribed to {topic_value}")
|
||||
logging.debug(f"Subscriber {subscriber_name} subscribed to {topic_name}")
|
||||
|
||||
# NOTE: The subscriber's signature needs to match the MDS (message data specification) of
|
||||
# the topic, otherwise, errors will arise. The MDS of a topic is set when the topic
|
||||
|
@ -28,7 +28,7 @@ class PyPubSubIslandEventQueue(IIslandEventQueue):
|
|||
# is new (hasn't been subscribed to before). If the topic is being subscribed to by
|
||||
# a subscriber for the first time, the topic's MDS will automatically be set
|
||||
# according to that subscriber's signature.
|
||||
self._pypubsub_publisher.subscribe(topicName=topic_value, listener=subscriber)
|
||||
self._pypubsub_publisher.subscribe(topicName=topic_name, listener=subscriber)
|
||||
self._keep_subscriber_strongref(subscriber)
|
||||
|
||||
def _keep_subscriber_strongref(self, subscriber: IslandEventSubscriber):
|
||||
|
@ -53,12 +53,12 @@ class PyPubSubIslandEventQueue(IIslandEventQueue):
|
|||
self._refs.append(subscriber)
|
||||
|
||||
def publish(self, topic: IslandEventTopic, event: Any = None):
|
||||
topic_value = topic.value # needs to be a string for pypubsub
|
||||
topic_name = topic.name # needs to be a string for pypubsub
|
||||
|
||||
logger.debug(f"Publishing {topic_value} event")
|
||||
logger.debug(f"Publishing {topic_name} event")
|
||||
|
||||
# NOTE: `event_data` needs to match the MDS (message data specification) of the topic,
|
||||
# otherwise, errors will arise. The MDS of a topic is set when the topic is created,
|
||||
# which in our case is when a subscriber subscribes to a topic (in `subscribe()`)
|
||||
# which is new (hasn't been subscribed to before).
|
||||
self._pypubsub_publisher.sendMessage(topicName=topic_value, event=event)
|
||||
self._pypubsub_publisher.sendMessage(topicName=topic_name, event=event)
|
||||
|
|
Loading…
Reference in New Issue