Skip to content

Commit

Permalink
Merge pull request #5 from Lash-L/asyncio_timeout
Browse files Browse the repository at this point in the history
Change to timeout from wait_for
  • Loading branch information
humbertogontijo authored Mar 1, 2023
2 parents 66a6b82 + f2b4c89 commit 311af16
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ roborock = "roborock.cli:main"
python = "^3.8"
click = ">=8"
aiohttp = "*"
async-timeout = "*"
pycryptodome = "~3.16.0"
pycryptodomex = {version = "~3.16.0", markers = "sys_platform == 'darwin'"}
paho-mqtt = "~1.6.1"
Expand Down
7 changes: 5 additions & 2 deletions roborock/roborock_queue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
from asyncio import Queue
from typing import Any
import async_timeout

from .exceptions import RoborockException

Expand All @@ -12,7 +13,9 @@ def __init__(self, protocol: int, *args):
self.protocol = protocol

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

async def async_get(self, timeout: float | int) -> tuple[Any, RoborockException | None]:
return await asyncio.wait_for(self.get(), timeout=timeout)
async with async_timeout.timeout(timeout):
return await self.get()
Empty file added tests/test_api.py
Empty file.

0 comments on commit 311af16

Please sign in to comment.