diff --git a/src/frequenz/channels/_broadcast.py b/src/frequenz/channels/_broadcast.py index d06c356c..e5ae0fad 100644 --- a/src/frequenz/channels/_broadcast.py +++ b/src/frequenz/channels/_broadcast.py @@ -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. @@ -290,7 +296,7 @@ def into_peekable(self) -> Peekable[T]: Returns: A `Peekable` instance. """ - self._active = False + self._deactivate() return Peekable(self._chan)