Skip to content

Commit 1e64ce6

Browse files
committed
Check for empty receivers after expired weakrefs are pruned
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
1 parent 708332b commit 1e64ce6

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/frequenz/channels/_broadcast.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,6 @@ async def send(self, message: _T, /) -> None:
381381
raise SenderError("The channel was closed", self) from ChannelClosedError(
382382
self._channel
383383
)
384-
if self._channel._auto_close_enabled and len(self._channel._receivers) == 0:
385-
raise SenderError("The channel was closed", self) from ChannelClosedError(
386-
self._channel
387-
)
388384
self._channel._latest = message
389385
stale_refs = []
390386
for _hash, recv_ref in self._channel._receivers.items():
@@ -395,6 +391,10 @@ async def send(self, message: _T, /) -> None:
395391
recv._enqueue(message)
396392
for _hash in stale_refs:
397393
del self._channel._receivers[_hash]
394+
if self._channel._auto_close_enabled and len(self._channel._receivers) == 0:
395+
raise SenderError("The channel was closed", self) from ChannelClosedError(
396+
self._channel
397+
)
398398
async with self._channel._recv_cv:
399399
self._channel._recv_cv.notify_all()
400400
# pylint: enable=protected-access

0 commit comments

Comments
 (0)