forked from p15670423/monkey
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 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
|
||||
"""
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue