mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-14 13:36:43 +03:00
Fix multiple calls to step hanging until timeout
This commit is contained in:
parent
fe733aad97
commit
c588c74c08
|
@ -174,6 +174,7 @@ class Sender:
|
|||
_next_ping: float
|
||||
_read_buffer: bytearray
|
||||
_write_drain_pending: bool
|
||||
_step_counter: int
|
||||
|
||||
@classmethod
|
||||
async def connect(
|
||||
|
@ -204,6 +205,7 @@ class Sender:
|
|||
_next_ping=asyncio.get_running_loop().time() + PING_DELAY,
|
||||
_read_buffer=bytearray(),
|
||||
_write_drain_pending=False,
|
||||
_step_counter=0,
|
||||
)
|
||||
|
||||
async def disconnect(self) -> None:
|
||||
|
@ -235,8 +237,16 @@ class Sender:
|
|||
return rx.result()
|
||||
|
||||
async def step(self) -> list[Updates]:
|
||||
ticket_number = self._step_counter
|
||||
|
||||
async with self.lock:
|
||||
if self._step_counter == ticket_number:
|
||||
# We're the one to drive IO.
|
||||
self._step_counter += 1
|
||||
return await self._step()
|
||||
else:
|
||||
# A different task drove IO.
|
||||
return []
|
||||
|
||||
async def _step(self) -> list[Updates]:
|
||||
self._try_fill_write()
|
||||
|
|
Loading…
Reference in New Issue
Block a user