mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-04-26 20:03:43 +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
|
lambda x, y: x.reply_to_msg_id == y
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_message(
|
async def _get_message(
|
||||||
self, target_message, indices, pending, timeout, condition):
|
self, target_message, indices, pending, timeout, condition):
|
||||||
"""
|
"""
|
||||||
Gets the next desired message under the desired 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
|
# Otherwise the next incoming response will be the one to use
|
||||||
pending[target_id] = future
|
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):
|
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
|
# Otherwise the next incoming response will be the one to use
|
||||||
future = asyncio.Future(loop=self._client.loop)
|
future = asyncio.Future(loop=self._client.loop)
|
||||||
self._pending_edits[target_id] = future
|
self._pending_edits[target_id] = future
|
||||||
return await self._get_result(future, start_time, timeout)
|
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):
|
async def wait_read(self, message=None, *, timeout=None):
|
||||||
"""
|
"""
|
||||||
|
@ -240,7 +246,10 @@ class Conversation(ChatGetter):
|
||||||
return
|
return
|
||||||
|
|
||||||
self._pending_reads[target_id] = future
|
self._pending_reads[target_id] = future
|
||||||
return await self._get_result(future, start_time, timeout)
|
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):
|
async def wait_event(self, event, *, timeout=None):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user