mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-18 11:06:39 +00: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
|
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.
|
clears the list from the queue itself. Returns ``None`` if cancelled.
|
||||||
"""
|
"""
|
||||||
ready = asyncio.ensure_future(self._ready.wait(), loop=self._loop)
|
ready = self._loop.create_task(self._ready.wait())
|
||||||
|
try:
|
||||||
done, pending = await asyncio.wait(
|
done, pending = await asyncio.wait(
|
||||||
[ready, cancellation],
|
[ready, cancellation],
|
||||||
return_when=asyncio.FIRST_COMPLETED,
|
return_when=asyncio.FIRST_COMPLETED,
|
||||||
loop=self._loop
|
loop=self._loop
|
||||||
)
|
)
|
||||||
|
except asyncio.CancelledError:
|
||||||
|
done = [cancellation]
|
||||||
|
|
||||||
if cancellation in done:
|
if cancellation in done:
|
||||||
ready.cancel()
|
ready.cancel()
|
||||||
return None
|
return None
|
||||||
|
@ -51,8 +51,8 @@ class Connection(abc.ABC):
|
|||||||
@property
|
@property
|
||||||
def disconnected(self):
|
def disconnected(self):
|
||||||
if not self._disconnected_future:
|
if not self._disconnected_future:
|
||||||
self._disconnected_future = asyncio.ensure_future(
|
self._disconnected_future = \
|
||||||
self._disconnected.wait(), loop=self._loop)
|
self._loop.create_task(self._disconnected.wait())
|
||||||
return self._disconnected_future
|
return self._disconnected_future
|
||||||
|
|
||||||
def clone(self):
|
def clone(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user