diff --git a/aiomqtt/client.py b/aiomqtt/client.py index 35f8536..690869f 100644 --- a/aiomqtt/client.py +++ b/aiomqtt/client.py @@ -233,7 +233,6 @@ def __init__( # noqa: C901, PLR0912, PLR0913, PLR0915 if max_queued_incoming_messages is None: max_queued_incoming_messages = 0 self._queue = queue_type(maxsize=max_queued_incoming_messages) - self.messages = self._messages() # Semaphore to limit the number of concurrent outgoing calls self._outgoing_calls_sem: asyncio.Semaphore | None @@ -447,6 +446,15 @@ async def publish( # noqa: PLR0913 # Wait for confirmation await self._wait_for(confirmation.wait(), timeout=timeout) + @property + def messages(self) -> AsyncGenerator[Message, None]: + warnings.warn('"client.messages" was renamed to "client.get_messages()"', DeprecationWarning) + return self.get_messages() + + def get_messages(self) -> AsyncGenerator[Message, None]: + # todo: raise Exception when disconnected + return self._messages() + async def _messages(self) -> AsyncGenerator[Message, None]: """Async generator that yields messages from the underlying message queue.""" while True: @@ -714,6 +722,7 @@ async def __aexit__( tb: TracebackType | None, ) -> None: """Disconnect from the broker.""" + if self._disconnected.done(): # Return early if the client is already disconnected if self._lock.locked():