forked from p15670423/monkey
Common: Create and partially implement PypubsubEventQueue
This commit is contained in:
parent
40219aa5ff
commit
bb76410bac
|
@ -1,25 +1,25 @@
|
||||||
from typing import Any, Callable, Sequence
|
from typing import Any, Callable, Sequence
|
||||||
|
|
||||||
|
from pubsub import ALL_TOPICS, pub
|
||||||
|
|
||||||
from common.events import AbstractEvent
|
from common.events import AbstractEvent
|
||||||
|
|
||||||
from .i_event_queue import IEventQueue
|
from .i_event_queue import IEventQueue
|
||||||
from pubsub import pub, ALL_TOPICS
|
|
||||||
|
|
||||||
|
|
||||||
class PypubsubEventQueue(IEventQueue):
|
class PypubsubEventQueue(IEventQueue):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def subscribe_all(subscriber: Callable[..., Any]):
|
def subscribe_all(subscriber: Callable[..., Any]):
|
||||||
pub.subscribe(listener=subscriber, topicName=ALL_TOPICS)
|
pub.subscribe(listener=subscriber, topicName=ALL_TOPICS)
|
||||||
|
|
||||||
def subscribe_types(self, types: Sequence[AbstractEvent], subscriber: Callable[..., Any]):
|
@staticmethod
|
||||||
"""
|
def subscribe_types(types: Sequence[AbstractEvent], subscriber: Callable[..., Any]):
|
||||||
Subscribes a subscriber to all specifed event types
|
for event_type in types:
|
||||||
|
PypubsubEventQueue._subscribe_type(event_type, subscriber)
|
||||||
|
|
||||||
:param types: Event types to which the subscriber should subscribe
|
def _subscribe_type(event_type: AbstractEvent, subscriber: Callable[..., Any]):
|
||||||
:param subscriber: Callable that should subscribe to events
|
event_type_name = event_type.__name__
|
||||||
"""
|
pub.subscribe(subscriber, event_type_name)
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
def subscribe_tags(self, tags: Sequence[str], subscriber: Callable[..., Any]):
|
def subscribe_tags(self, tags: Sequence[str], subscriber: Callable[..., Any]):
|
||||||
"""
|
"""
|
||||||
|
@ -40,4 +40,3 @@ class PypubsubEventQueue(IEventQueue):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue