Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
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
14 changes: 7 additions & 7 deletions broadcaster/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ async def subscribe(self, channel: str) -> AsyncIterator["Subscriber"]:
self._subscribers[channel] = set([queue])
else:
self._subscribers[channel].add(queue)

yield Subscriber(queue)

self._subscribers[channel].remove(queue)
if not self._subscribers.get(channel):
del self._subscribers[channel]
await self._backend.unsubscribe(channel)
try:
yield Subscriber(queue)
finally:
self._subscribers[channel].remove(queue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a unit test for it?

if not self._subscribers.get(channel):
del self._subscribers[channel]
await self._backend.unsubscribe(channel)
finally:
await queue.put(None)

Expand Down