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:
Lonami Exo 2019-05-27 14:10:38 +02:00
parent e5485f3d54
commit 0b41454b01

View File

@ -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):
"""