Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update client.py #271

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion aiomqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down
Loading