From 98bdf910e481a40ba5dff84ecbc127d9f7170d84 Mon Sep 17 00:00:00 2001 From: udf Date: Sun, 8 Apr 2018 22:13:20 +0200 Subject: [PATCH] make await_event stop propagation only if the filter raises --- uniborg/telethon.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/uniborg/telethon.py b/uniborg/telethon.py index 35270e6..812457d 100644 --- a/uniborg/telethon.py +++ b/uniborg/telethon.py @@ -87,9 +87,12 @@ class Uniborg(TelegramClient): @self.on(event_matcher) async def cb(event): - if filter is None or await filter(event): + try: + if filter is None or await filter(event): + fut.set_result(event) + except telethon.events.StopPropagation: fut.set_result(event) - raise telethon.events.StopPropagation + raise fut.add_done_callback( lambda _: self.remove_event_handler(cb, event_matcher))