Add get_handler_by_type() method in Processor

This commit is contained in:
Christophe Bedard 2019-12-31 20:16:24 -05:00
parent fe1e856372
commit 06efe1a169

View file

@ -332,6 +332,18 @@ class Processor():
for handler in handlers: for handler in handlers:
handler.register_processor(self) handler.register_processor(self)
def get_handler_by_type(
self,
handler_type: Type,
) -> Union[EventHandler, None]:
"""
Get an existing EventHandler instance from its type.
:param handler_type: the type of EventHandler subclass to find
:return: the EventHandler instance if found, otherwise `None`
"""
return next((handler for handler in self._expanded_handlers if type(handler) is handler_type), None)
@staticmethod @staticmethod
def get_event_names( def get_event_names(
events: List[DictEvent], events: List[DictEvent],