xmlstream: handle done tasks in wait_until

and handle other loops properly
This commit is contained in:
mathieui 2021-01-23 15:41:13 +01:00
parent 370abb1d98
commit 0eed84d0b2

View file

@ -1142,9 +1142,15 @@ class XMLStream(asyncio.BaseProtocol):
:param int timeout: Timeout
"""
fut = asyncio.Future()
def result_handler(event_data):
if not fut.done():
fut.set_result(event_data)
else:
log.debug("Future registered on event '%s' was alredy done", event)
self.add_event_handler(
event,
fut.set_result,
result_handler,
disposable=True,
)
return await asyncio.wait_for(fut, timeout)
return await asyncio.wait_for(fut, timeout, loop=self.loop)