From 392fea6e325d2dd956c7e8214971b3e978f563f7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 4 Feb 2019 11:46:57 +0100 Subject: [PATCH] Refactor Dispatcher's worker Closes #211 --- pyrogram/client/dispatcher/dispatcher.py | 39 ++++++++++++------------ 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/pyrogram/client/dispatcher/dispatcher.py b/pyrogram/client/dispatcher/dispatcher.py index b9acf519..cb22a48c 100644 --- a/pyrogram/client/dispatcher/dispatcher.py +++ b/pyrogram/client/dispatcher/dispatcher.py @@ -130,34 +130,33 @@ class Dispatcher: parsed_update, handler_type = ( parser(update, users, chats) - if parser - else (None, type) + if parser is not None + else (None, type(None)) ) for group in self.groups.values(): - try: - for handler in group: - args = None + for handler in group: + args = None - if isinstance(handler, RawUpdateHandler): - args = (update, users, chats) - elif isinstance(handler, handler_type): - if handler.check(parsed_update): - args = (parsed_update,) + if isinstance(handler, handler_type): + if handler.check(parsed_update): + args = (parsed_update,) + elif isinstance(handler, RawUpdateHandler): + args = (update, users, chats) - if args is None: - continue + if args is None: + continue - try: - handler.callback(self.client, *args) - except StopIteration: - raise - except Exception as e: - log.error(e, exc_info=True) + try: + handler.callback(self.client, *args) + except pyrogram.StopPropagation: + raise + except Exception as e: + log.error(e, exc_info=True) - break - except StopIteration: break + except pyrogram.StopPropagation: + pass except Exception as e: log.error(e, exc_info=True)