From bb76410bac2733f9ba62bbcbeb631c6d563ad0cc Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Fri, 5 Aug 2022 19:11:33 +0530 Subject: [PATCH] Common: Create and partially implement PypubsubEventQueue --- .../event_queue/pypubsub_event_queue.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/monkey/common/event_queue/pypubsub_event_queue.py b/monkey/common/event_queue/pypubsub_event_queue.py index 486233fd0..898b073e6 100644 --- a/monkey/common/event_queue/pypubsub_event_queue.py +++ b/monkey/common/event_queue/pypubsub_event_queue.py @@ -1,25 +1,25 @@ from typing import Any, Callable, Sequence +from pubsub import ALL_TOPICS, pub + from common.events import AbstractEvent + from .i_event_queue import IEventQueue -from pubsub import pub, ALL_TOPICS class PypubsubEventQueue(IEventQueue): - @staticmethod def subscribe_all(subscriber: Callable[..., Any]): pub.subscribe(listener=subscriber, topicName=ALL_TOPICS) - def subscribe_types(self, types: Sequence[AbstractEvent], subscriber: Callable[..., Any]): - """ - Subscribes a subscriber to all specifed event types + @staticmethod + def subscribe_types(types: Sequence[AbstractEvent], subscriber: Callable[..., Any]): + for event_type in types: + PypubsubEventQueue._subscribe_type(event_type, subscriber) - :param types: Event types to which the subscriber should subscribe - :param subscriber: Callable that should subscribe to events - """ - - pass + def _subscribe_type(event_type: AbstractEvent, subscriber: Callable[..., Any]): + event_type_name = event_type.__name__ + pub.subscribe(subscriber, event_type_name) def subscribe_tags(self, tags: Sequence[str], subscriber: Callable[..., Any]): """ @@ -40,4 +40,3 @@ class PypubsubEventQueue(IEventQueue): """ pass -