Skip to content

Commit 8559a81

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

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/frequenz/channels/_broadcast.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +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-
)
388-
self._channel._latest = message
389384
stale_refs = []
390385
for _hash, recv_ref in self._channel._receivers.items():
391386
recv = recv_ref()
@@ -395,6 +390,11 @@ async def send(self, message: _T, /) -> None:
395390
recv._enqueue(message)
396391
for _hash in stale_refs:
397392
del self._channel._receivers[_hash]
393+
if self._channel._auto_close_enabled and len(self._channel._receivers) == 0:
394+
raise SenderError("The channel was closed", self) from ChannelClosedError(
395+
self._channel
396+
)
397+
self._channel._latest = message
398398
async with self._channel._recv_cv:
399399
self._channel._recv_cv.notify_all()
400400
# pylint: enable=protected-access

0 commit comments

Comments
 (0)