TelegramClient: allow the event handler decorator to work while the loop is running

This commit is contained in:
Dan Elkouby 2018-04-08 01:01:04 +03:00
parent abcd09e7d0
commit b6947e9e6d

View File

@ -2185,7 +2185,10 @@ class TelegramClient(TelegramBareClient):
for instance ``events.NewMessage``.
"""
def decorator(f):
self._loop.run_until_complete(self.add_event_handler(f, event))
if self._loop.is_running():
asyncio.ensure_future(self.add_event_handler(f, event))
else:
self._loop.run_until_complete(self.add_event_handler(f, event))
return f
return decorator