mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Properly handle cancellation in _ReadyQueue
This commit is contained in:
parent
105bd52eee
commit
2d275989cb
|
@ -111,12 +111,16 @@ class _ReadyQueue:
|
|||
Returns a list of all the items added to the queue until now and
|
||||
clears the list from the queue itself. Returns ``None`` if cancelled.
|
||||
"""
|
||||
ready = asyncio.ensure_future(self._ready.wait(), loop=self._loop)
|
||||
done, pending = await asyncio.wait(
|
||||
[ready, cancellation],
|
||||
return_when=asyncio.FIRST_COMPLETED,
|
||||
loop=self._loop
|
||||
)
|
||||
ready = self._loop.create_task(self._ready.wait())
|
||||
try:
|
||||
done, pending = await asyncio.wait(
|
||||
[ready, cancellation],
|
||||
return_when=asyncio.FIRST_COMPLETED,
|
||||
loop=self._loop
|
||||
)
|
||||
except asyncio.CancelledError:
|
||||
done = [cancellation]
|
||||
|
||||
if cancellation in done:
|
||||
ready.cancel()
|
||||
return None
|
||||
|
|
|
@ -51,8 +51,8 @@ class Connection(abc.ABC):
|
|||
@property
|
||||
def disconnected(self):
|
||||
if not self._disconnected_future:
|
||||
self._disconnected_future = asyncio.ensure_future(
|
||||
self._disconnected.wait(), loop=self._loop)
|
||||
self._disconnected_future = \
|
||||
self._loop.create_task(self._disconnected.wait())
|
||||
return self._disconnected_future
|
||||
|
||||
def clone(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user