Common: Change IEventQueue and PyPubSubEventQueue's subscribe_types() -> subscribe_type()
This commit is contained in:
parent
ae666d3dd3
commit
3cef54c09c
|
@ -1,5 +1,5 @@
|
||||||
from abc import ABC, abstractstaticmethod
|
from abc import ABC, abstractstaticmethod
|
||||||
from typing import Any, Callable, Sequence
|
from typing import Any, Callable
|
||||||
|
|
||||||
from common.events import AbstractEvent
|
from common.events import AbstractEvent
|
||||||
|
|
||||||
|
@ -20,13 +20,11 @@ class IEventQueue(ABC):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractstaticmethod
|
@abstractstaticmethod
|
||||||
def subscribe_types(
|
def subscribe_type(event_type: AbstractEvent, subscriber: Callable[[AbstractEvent], None]):
|
||||||
types: Sequence[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
|
:param subscriber: Callable that should subscribe to events
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import Any, Callable, Sequence
|
from typing import Any, Callable
|
||||||
|
|
||||||
from pubsub import pub
|
from pubsub import pub
|
||||||
|
|
||||||
|
@ -13,10 +13,7 @@ class PyPubSubEventQueue(IEventQueue):
|
||||||
pub.subscribe(listener=subscriber, topicName=pub.ALL_TOPICS)
|
pub.subscribe(listener=subscriber, topicName=pub.ALL_TOPICS)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def subscribe_types(
|
def subscribe_type(event_type: AbstractEvent, subscriber: Callable[[AbstractEvent], None]):
|
||||||
types: Sequence[AbstractEvent], subscriber: Callable[[AbstractEvent], None]
|
|
||||||
):
|
|
||||||
for event_type in types:
|
|
||||||
# pypubsub.pub.subscribe needs a string as the topic/event name
|
# pypubsub.pub.subscribe needs a string as the topic/event name
|
||||||
event_type_name = event_type.__name__
|
event_type_name = event_type.__name__
|
||||||
pub.subscribe(listener=subscriber, topicName=event_type_name)
|
pub.subscribe(listener=subscriber, topicName=event_type_name)
|
||||||
|
|
Loading…
Reference in New Issue