Skip to content

Commit 6b4c22c

Browse files
committed
Add a private method to deactivate Broadcast receivers
... 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 <[email protected]>
1 parent 67dbfa1 commit 6b4c22c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/frequenz/channels/_broadcast.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ async def ready(self) -> None:
270270
async with self._chan.recv_cv:
271271
await self._chan.recv_cv.wait()
272272

273+
def _deactivate(self) -> None:
274+
"""Set the receiver as inactive and remove it from the channel."""
275+
self._active = False
276+
if self._uuid in self._chan.receivers:
277+
del self._chan.receivers[self._uuid]
278+
273279
def consume(self) -> T:
274280
"""Return the latest value once `ready` is complete.
275281
@@ -290,7 +296,7 @@ def into_peekable(self) -> Peekable[T]:
290296
Returns:
291297
A `Peekable` instance.
292298
"""
293-
self._active = False
299+
self._deactivate()
294300
return Peekable(self._chan)
295301

296302

0 commit comments

Comments
 (0)