Common: Change IEventQueue and PyPubSubEventQueue's subscribe_types() -> subscribe_type()

This commit is contained in:
Shreya Malviya 2022-08-09 11:53:03 +05:30
parent ae666d3dd3
commit 3cef54c09c
2 changed files with 9 additions and 14 deletions

View File

@ -1,5 +1,5 @@
from abc import ABC, abstractstaticmethod
from typing import Any, Callable, Sequence
from typing import Any, Callable
from common.events import AbstractEvent
@ -20,13 +20,11 @@ class IEventQueue(ABC):
pass
@abstractstaticmethod
def subscribe_types(
types: Sequence[AbstractEvent], subscriber: Callable[[AbstractEvent], None]
):
def subscribe_type(event_type: AbstractEvent, subscriber: Callable[[AbstractEvent], None]):
"""
Subscribes a subscriber to all specifed event types
Subscribes a subscriber to the specifed event type
:param types: Event types to which the subscriber should subscribe
:param event_type: Event type to which the subscriber should subscribe
:param subscriber: Callable that should subscribe to events
"""

View File

@ -1,4 +1,4 @@
from typing import Any, Callable, Sequence
from typing import Any, Callable
from pubsub import pub
@ -13,10 +13,7 @@ class PyPubSubEventQueue(IEventQueue):
pub.subscribe(listener=subscriber, topicName=pub.ALL_TOPICS)
@staticmethod
def subscribe_types(
types: Sequence[AbstractEvent], subscriber: Callable[[AbstractEvent], None]
):
for event_type in types:
def subscribe_type(event_type: AbstractEvent, subscriber: Callable[[AbstractEvent], None]):
# pypubsub.pub.subscribe needs a string as the topic/event name
event_type_name = event_type.__name__
pub.subscribe(listener=subscriber, topicName=event_type_name)