Skip to content

Commit eaa4dee

Browse files
committed
fix: change to timeout from wait_for
wait_for creates a task, async_timeout does the same work and avoids the task creation
1 parent 28dcad8 commit eaa4dee

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ roborock = "roborock.cli:main"
1414
python = "^3.8"
1515
click = ">=8"
1616
aiohttp = "*"
17+
async-timeout = "*"
1718
pycryptodome = "~3.16.0"
1819
pycryptodomex = {version = "~3.16.0", markers = "sys_platform == 'darwin'"}
1920
paho-mqtt = "~1.6.1"

roborock/roborock_queue.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
from asyncio import Queue
33
from typing import Any
4+
import async_timeout
45

56
from roborock import RoborockException
67

@@ -12,7 +13,10 @@ def __init__(self, protocol: int, *args):
1213
self.protocol = protocol
1314

1415
async def async_put(self, item: tuple[Any, RoborockException | None], timeout: float | int) -> None:
15-
return await asyncio.wait_for(self.put(item), timeout=timeout)
16+
async with async_timeout.timeout(timeout):
17+
await self.put(item)
1618

1719
async def async_get(self, timeout: float | int) -> tuple[Any, RoborockException | None]:
20+
async with async_timeout.timeout(timeout):
21+
await self.get()
1822
return await asyncio.wait_for(self.get(), timeout=timeout)

0 commit comments

Comments
 (0)