Skip to content

Commit

Permalink
Add a private method to deactivate Broadcast receivers
Browse files Browse the repository at this point in the history
... that would also remove the receiver from the channel,  so that
messages don't keep getting sent to deactivated receivers.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
  • Loading branch information
shsms committed Jan 23, 2023
1 parent 67dbfa1 commit 6b4c22c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/frequenz/channels/_broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ async def ready(self) -> None:
async with self._chan.recv_cv:
await self._chan.recv_cv.wait()

def _deactivate(self) -> None:
"""Set the receiver as inactive and remove it from the channel."""
self._active = False
if self._uuid in self._chan.receivers:
del self._chan.receivers[self._uuid]

def consume(self) -> T:
"""Return the latest value once `ready` is complete.
Expand All @@ -290,7 +296,7 @@ def into_peekable(self) -> Peekable[T]:
Returns:
A `Peekable` instance.
"""
self._active = False
self._deactivate()
return Peekable(self._chan)


Expand Down

0 comments on commit 6b4c22c

Please sign in to comment.