mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Fix conversation setting result on cancelled futures
On timeout, they are cancelled. On a new message arriving, we pop and set the result unconditionally. conv.send_message('Talk to me please') conv.get_response() try: conv.get_response(timeout=0.1) except asyncio.TimeoutError: pass conv.send_message('One more time...') conv.get_response() # errors unless above is commented
This commit is contained in:
parent
e5485f3d54
commit
0b41454b01
|
@ -138,7 +138,7 @@ class Conversation(ChatGetter):
|
|||
lambda x, y: x.reply_to_msg_id == y
|
||||
)
|
||||
|
||||
def _get_message(
|
||||
async def _get_message(
|
||||
self, target_message, indices, pending, timeout, condition):
|
||||
"""
|
||||
Gets the next desired message under the desired condition.
|
||||
|
@ -193,7 +193,10 @@ class Conversation(ChatGetter):
|
|||
|
||||
# Otherwise the next incoming response will be the one to use
|
||||
pending[target_id] = future
|
||||
return self._get_result(future, start_time, timeout)
|
||||
try:
|
||||
return await self._get_result(future, start_time, timeout)
|
||||
finally:
|
||||
pending.pop(target_id, None)
|
||||
|
||||
async def get_edit(self, message=None, *, timeout=None):
|
||||
"""
|
||||
|
@ -221,7 +224,10 @@ class Conversation(ChatGetter):
|
|||
# Otherwise the next incoming response will be the one to use
|
||||
future = asyncio.Future(loop=self._client.loop)
|
||||
self._pending_edits[target_id] = future
|
||||
try:
|
||||
return await self._get_result(future, start_time, timeout)
|
||||
finally:
|
||||
self._pending_edits.pop(target_id, None)
|
||||
|
||||
async def wait_read(self, message=None, *, timeout=None):
|
||||
"""
|
||||
|
@ -240,7 +246,10 @@ class Conversation(ChatGetter):
|
|||
return
|
||||
|
||||
self._pending_reads[target_id] = future
|
||||
try:
|
||||
return await self._get_result(future, start_time, timeout)
|
||||
finally:
|
||||
self._pending_reads.pop(target_id, None)
|
||||
|
||||
async def wait_event(self, event, *, timeout=None):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user