Skip to content

Commit 51e7198

Browse files
committed
Add set_resend_latest method to ChannelRegistry class
This would allow better control over the channels, where needed. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 3562004 commit 51e7198

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/frequenz/sdk/actor/_channel_registry.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@ def __init__(self, *, name: str) -> None:
2828
self._name = name
2929
self._channels: dict[str, Broadcast[typing.Any]] = {}
3030

31+
def set_resend_latest(self, key: str, resend_latest: bool) -> None:
32+
"""Set the `resend_latest` flag for a given channel.
33+
34+
This flag controls whether the latest value of the channel should be resent to
35+
new receivers, in slow streams.
36+
37+
`resend_latest` is `False` by default. It is safe to be set in data/reporting
38+
channels, but is not recommended for use in channels that stream control
39+
instructions.
40+
41+
Args:
42+
key: A key to identify the channel.
43+
resend_latest: Whether to resend the latest value to new receivers, for the
44+
given channel.
45+
"""
46+
if key not in self._channels:
47+
self._channels[key] = Broadcast(f"{self._name}-{key}")
48+
# This attribute is protected in the current version of the channels library,
49+
# but that will change in the future.
50+
self._channels[ # pylint: disable=protected-access
51+
key
52+
]._resend_latest = resend_latest
53+
3154
def new_sender(self, key: str) -> Sender[typing.Any]:
3255
"""Get a sender to a dynamically created channel with the given key.
3356

0 commit comments

Comments
 (0)