Skip to content

Commit 486abce

Browse files
committed
Track sender count on sender create and close
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
1 parent f4b78be commit 486abce

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/frequenz/channels/_broadcast.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ def __init__(self, *, name: str, resend_latest: bool = False) -> None:
207207
self._recv_cv: Condition = Condition()
208208
"""The condition to wait for data in the channel's buffer."""
209209

210+
self._sender_count: int = 0
211+
"""The number of senders attached to this channel."""
212+
210213
self._receivers: dict[
211214
int, weakref.ReferenceType[_Receiver[ChannelMessageT]]
212215
] = {}
@@ -337,6 +340,8 @@ def __init__(self, channel: Broadcast[_T], /) -> None:
337340
self._closed: bool = False
338341
"""Whether this sender is closed."""
339342

343+
self._channel._sender_count += 1
344+
340345
@override
341346
async def send(self, message: _T, /) -> None:
342347
"""Send a message to all broadcast receivers.
@@ -380,6 +385,7 @@ def close(self) -> None:
380385
[SenderError][frequenz.channels.SenderError].
381386
"""
382387
self._closed = True
388+
self._channel._sender_count -= 1
383389

384390
@override
385391
def clone(self) -> _Sender[_T]:

0 commit comments

Comments
 (0)