Skip to content

Commit

Permalink
Update client.py
Browse files Browse the repository at this point in the history
Fixes x268
  • Loading branch information
spacemanspiff2007 authored Jan 31, 2024
1 parent 13b44fb commit 701a9e1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion aiomqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ 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()
self.messages: AsyncGenerator[Message, None] | None = None

# Semaphore to limit the number of concurrent outgoing calls
self._outgoing_calls_sem: asyncio.Semaphore | None
Expand Down Expand Up @@ -705,6 +705,8 @@ async def __aenter__(self) -> Self:
# Reset `_disconnected` if it's already in completed state after connecting
if self._disconnected.done():
self._disconnected = asyncio.Future()

self.messages = self._messages()
return self

async def __aexit__(
Expand All @@ -714,6 +716,9 @@ async def __aexit__(
tb: TracebackType | None,
) -> None:
"""Disconnect from the broker."""

self.messages = None

if self._disconnected.done():
# Return early if the client is already disconnected
if self._lock.locked():
Expand Down

0 comments on commit 701a9e1

Please sign in to comment.