mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +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
|
_next_ping: float
|
||||||
_read_buffer: bytearray
|
_read_buffer: bytearray
|
||||||
_write_drain_pending: bool
|
_write_drain_pending: bool
|
||||||
|
_step_counter: int
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def connect(
|
async def connect(
|
||||||
|
@ -204,6 +205,7 @@ class Sender:
|
||||||
_next_ping=asyncio.get_running_loop().time() + PING_DELAY,
|
_next_ping=asyncio.get_running_loop().time() + PING_DELAY,
|
||||||
_read_buffer=bytearray(),
|
_read_buffer=bytearray(),
|
||||||
_write_drain_pending=False,
|
_write_drain_pending=False,
|
||||||
|
_step_counter=0,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def disconnect(self) -> None:
|
async def disconnect(self) -> None:
|
||||||
|
@ -235,8 +237,16 @@ class Sender:
|
||||||
return rx.result()
|
return rx.result()
|
||||||
|
|
||||||
async def step(self) -> list[Updates]:
|
async def step(self) -> list[Updates]:
|
||||||
|
ticket_number = self._step_counter
|
||||||
|
|
||||||
async with self.lock:
|
async with self.lock:
|
||||||
return await self._step()
|
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]:
|
async def _step(self) -> list[Updates]:
|
||||||
self._try_fill_write()
|
self._try_fill_write()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user