Skip to content

Commit

Permalink
fix responce timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
toxazhl committed Mar 14, 2024
1 parent ff32659 commit 23ebecc
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions fastmqtt/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ async def __aexit__(self, exc_type, exc_value, traceback):
async def _callback(self, message: Message) -> None:
correlation_data = message.properties.get("CorrelationData")
if correlation_data is None:
raise FastMQTTError(
f"correlation_data is None in response callback ({message.topic})"
)
raise FastMQTTError(f"correlation_data is None in response callback ({message.topic})")

future = self._futures.pop(correlation_data)
future.set_result(message)
Expand All @@ -81,6 +79,7 @@ async def request(
qos: int = 0,
retain: bool = False,
properties: dict[str, Any] | None = None,
timeout: float | None = None,
) -> Message:
if properties is None:
properties = {}
Expand All @@ -96,14 +95,15 @@ async def request(
future = asyncio.Future[Message]()
self._futures[correlation_data] = future
try:
await self._fastmqtt.publish(
topic=topic,
payload=payload,
qos=qos,
retain=retain,
properties=properties,
)
return await future
async with asyncio.timeout(timeout or self._default_timeout):
await self._fastmqtt.publish(
topic=topic,
payload=payload,
qos=qos,
retain=retain,
properties=properties,
)
return await future

finally:
self._futures.pop(correlation_data, None)

0 comments on commit 23ebecc

Please sign in to comment.