From 9dff15bd4f364c03fabdc8905e7dd755ecba2c7c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 26 Jun 2018 13:45:31 +0200 Subject: [PATCH] Make run() accept coroutine functions --- pyrogram/client/client.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 8c34ea29..61b499a3 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -20,6 +20,7 @@ import asyncio import base64 import binascii import getpass +import inspect import json import logging import math @@ -328,11 +329,18 @@ class Client(Methods, BaseClient): run = asyncio.get_event_loop().run_until_complete run(self.start()) - run(coroutine or self.idle()) - if coroutine: + run( + coroutine if inspect.iscoroutine(coroutine) + else coroutine() if coroutine + else self.idle() + ) + + if self.is_started: run(self.stop()) + return coroutine + def add_handler(self, handler, group: int = 0): """Use this method to register an update handler.