From 5ca422b31425da9c0d3cb070d1856496bd046170 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 28 Dec 2022 00:19:28 +0100 Subject: [PATCH] Create a future result before sending its request --- pyrogram/session/session.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index df7ae6c4..e64ea793 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -282,6 +282,9 @@ class Session: message = self.msg_factory(data) msg_id = message.msg_id + if wait_response: + self.results[msg_id] = Result() + log.debug("Sent: %s", message) payload = await self.loop.run_in_executor( @@ -297,8 +300,6 @@ class Session: await self.connection.send(payload) if wait_response: - self.results[msg_id] = Result() - try: await asyncio.wait_for(self.results[msg_id].event.wait(), timeout) except asyncio.TimeoutError: