Skip to content

Commit bd7b04e

Browse files
committed
Replace "value" with "message"
We prefer to use the term "message" as what's transported in a channel, as "value" is too generic and used in many other contexts. This means changing the code too, so `Selected.value` is now `Selected.message`. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 665ad01 commit bd7b04e

18 files changed

+156
-156
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ async def send(
141141
await sender.send(f"{sender}: {counter}")
142142
counter += 1
143143
elif selected_from(selected, control_command):
144-
print(f"{sender}: Received command: {selected.value.name}")
145-
match selected.value:
144+
print(f"{sender}: Received command: {selected.message.name}")
145+
match selected.message:
146146
case Command.STOP_SENDER:
147147
print(f"{sender}: Stopping")
148148
break
@@ -166,13 +166,13 @@ async def receive(
166166
merged = merge(*receivers)
167167
async for selected in select(merged, timer, control_command):
168168
if selected_from(selected, merged):
169-
message = selected.value
169+
message = selected.message
170170
print(f"receive: Received {message=}")
171171
timer.reset()
172172
print(f"{timer=}")
173173
elif selected_from(selected, control_command):
174-
print(f"receive: received command: {selected.value.name}")
175-
match selected.value:
174+
print(f"receive: received command: {selected.message.name}")
175+
match selected.message:
176176
case Command.PING:
177177
print("receive: Ping received, reply with pong")
178178
await control_reply.send(Reply(ReplyCommand.PONG, "receive"))
@@ -181,7 +181,7 @@ async def receive(
181181
case _ as unknown:
182182
assert_never(unknown)
183183
elif selected_from(selected, timer):
184-
drift = selected.value
184+
drift = selected.message
185185
print(
186186
f"receive: No data received for {timer.interval + drift} seconds, "
187187
"giving up"

RELEASE_NOTES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@
7979

8080
* `Peekable`
8181

82-
This class was removed because it was merely a shortcut to a receiver that caches the last value received. It did not fit the channel abstraction well and was infrequently used.
82+
This class was removed because it was merely a shortcut to a receiver that caches the last message received. It did not fit the channel abstraction well and was infrequently used.
8383

84-
You can replace it with a task that receives and retains the last value.
84+
You can replace it with a task that receives and retains the last message.
8585

8686
* `Broadcast.new_peekable()`
8787

src/frequenz/channels/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
* [merge][frequenz.channels.merge]: Merge messages coming from multiple receivers into
3333
a single stream.
3434
35-
* [select][frequenz.channels.select]: Iterate over the values of all
36-
[receivers][frequenz.channels.Receiver] as new values become available.
35+
* [select][frequenz.channels.select]: Iterate over the messages of all
36+
[receivers][frequenz.channels.Receiver] as new messages become available.
3737
3838
Exception classes:
3939

src/frequenz/channels/_anycast.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Anycast(Generic[_T]):
7979
When the channel is not needed anymore, it should be closed with the
8080
[`close()`][frequenz.channels.Anycast.close] method. This will prevent further
8181
attempts to [`send()`][frequenz.channels.Sender.send] data. Receivers will still be
82-
able to drain the pending values on the channel, but after that, subsequent
82+
able to drain the pending messages on the channel, but after that, subsequent
8383
[`receive()`][frequenz.channels.Receiver.receive] calls will raise a
8484
[`ReceiverStoppedError`][frequenz.channels.ReceiverStoppedError] exception.
8585
@@ -181,15 +181,15 @@ async def main() -> None:
181181
sender_1 sending 11
182182
sender_1 sending 12
183183
Anycast channel [Anycast:numbers:_Sender] is full, blocking sender until a receiver
184-
consumes a value
184+
consumes a message
185185
sender_2 sending 20
186186
Anycast channel [Anycast:numbers:_Sender] is full, blocking sender until a receiver
187-
consumes a value
187+
consumes a message
188188
receiver_1 received 10
189189
receiver_1 received 11
190190
sender_2 sending 21
191191
Anycast channel [Anycast:numbers:_Sender] is full, blocking sender until a receiver
192-
consumes a value
192+
consumes a message
193193
receiver_1 received 12
194194
receiver_1 received 20
195195
receiver_1 received 21
@@ -219,16 +219,16 @@ def __init__(self, *, name: str, limit: int = 10) -> None:
219219
self._send_cv: Condition = Condition()
220220
"""The condition to wait for free space in the channel's buffer.
221221
222-
If the channel's buffer is full, then the sender waits for values to
222+
If the channel's buffer is full, then the sender waits for messages to
223223
get consumed using this condition until there's some free space
224224
available in the channel's buffer.
225225
"""
226226

227227
self._recv_cv: Condition = Condition()
228-
"""The condition to wait for values in the channel's buffer.
228+
"""The condition to wait for messages in the channel's buffer.
229229
230-
If the channel's buffer is empty, then the receiver waits for values
231-
using this condition until there's a value available in the channel's
230+
If the channel's buffer is empty, then the receiver waits for messages
231+
using this condition until there's a message available in the channel's
232232
buffer.
233233
"""
234234

@@ -255,11 +255,11 @@ def is_closed(self) -> bool:
255255

256256
@property
257257
def limit(self) -> int:
258-
"""The maximum number of values that can be stored in the channel's buffer.
258+
"""The maximum number of messages that can be stored in the channel's buffer.
259259
260260
If the length of channel's buffer reaches the limit, then the sender
261261
blocks at the [send()][frequenz.channels.Sender.send] method until
262-
a value is consumed.
262+
a message is consumed.
263263
"""
264264
maxlen = self._deque.maxlen
265265
assert maxlen is not None
@@ -271,7 +271,7 @@ async def close(self) -> None:
271271
Any further attempts to [send()][frequenz.channels.Sender.send] data
272272
will return `False`.
273273
274-
Receivers will still be able to drain the pending values on the channel,
274+
Receivers will still be able to drain the pending messages on the channel,
275275
but after that, subsequent
276276
[receive()][frequenz.channels.Receiver.receive] calls will return `None`
277277
immediately.
@@ -342,7 +342,7 @@ async def send(self, msg: _T) -> None:
342342
if len(self._chan._deque) == self._chan._deque.maxlen:
343343
_logger.warning(
344344
"Anycast channel [%s] is full, blocking sender until a receiver "
345-
"consumes a value",
345+
"consumes a message",
346346
self,
347347
)
348348
while len(self._chan._deque) == self._chan._deque.maxlen:
@@ -367,7 +367,7 @@ def __repr__(self) -> str:
367367

368368

369369
class _Empty:
370-
"""A sentinel value to indicate that a value has not been set."""
370+
"""A sentinel to indicate that a message has not been set."""
371371

372372

373373
class _Receiver(Receiver[_T]):
@@ -389,9 +389,9 @@ def __init__(self, chan: Anycast[_T]) -> None:
389389
self._next: _T | type[_Empty] = _Empty
390390

391391
async def ready(self) -> bool:
392-
"""Wait until the receiver is ready with a value or an error.
392+
"""Wait until the receiver is ready with a message or an error.
393393
394-
Once a call to `ready()` has finished, the value should be read with
394+
Once a call to `ready()` has finished, the message should be read with
395395
a call to `consume()` (`receive()` or iterated over). The receiver will
396396
remain ready (this method will return immediately) until it is
397397
consumed.
@@ -416,10 +416,10 @@ async def ready(self) -> bool:
416416
return True
417417

418418
def consume(self) -> _T:
419-
"""Return the latest value once `ready()` is complete.
419+
"""Return the latest message once `ready()` is complete.
420420
421421
Returns:
422-
The next value that was received.
422+
The next message that was received.
423423
424424
Raises:
425425
ReceiverStoppedError: If the receiver stopped producing messages.

src/frequenz/channels/_broadcast.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ def __init__(self, *, name: str, resend_latest: bool = False) -> None:
190190
name: The name of the channel. This is for logging purposes, and it will be
191191
shown in the string representation of the channel.
192192
resend_latest: When True, every time a new receiver is created with
193-
`new_receiver`, it will automatically get sent the latest value on the
194-
channel. This allows new receivers on slow streams to get the latest
195-
value as soon as they are created, without having to wait for the next
196-
message on the channel to arrive. It is safe to be set in
197-
data/reporting channels, but is not recommended for use in channels that
198-
stream control instructions.
193+
`new_receiver`, the last message seen by the channel will be sent to the
194+
new receiver automatically. This allows new receivers on slow streams to
195+
get the latest message as soon as they are created, without having to
196+
wait for the next message on the channel to arrive. It is safe to be
197+
set in data/reporting channels, but is not recommended for use in
198+
channels that stream control instructions.
199199
"""
200200
self._name: str = name
201201
"""The name of the broadcast channel.
@@ -213,14 +213,14 @@ def __init__(self, *, name: str, resend_latest: bool = False) -> None:
213213
"""Whether the channel is closed."""
214214

215215
self._latest: _T | None = None
216-
"""The latest value sent to the channel."""
216+
"""The latest message sent to the channel."""
217217

218218
self.resend_latest: bool = resend_latest
219-
"""Whether to resend the latest value to new receivers.
219+
"""Whether to resend the latest message to new receivers.
220220
221221
When `True`, every time a new receiver is created with `new_receiver`, it will
222-
automatically get sent the latest value on the channel. This allows new
223-
receivers on slow streams to get the latest value as soon as they are created,
222+
automatically get sent the latest message on the channel. This allows new
223+
receivers on slow streams to get the latest message as soon as they are created,
224224
without having to wait for the next message on the channel to arrive.
225225
226226
It is safe to be set in data/reporting channels, but is not recommended for use
@@ -419,9 +419,9 @@ def __len__(self) -> int:
419419
return len(self._q)
420420

421421
async def ready(self) -> bool:
422-
"""Wait until the receiver is ready with a value or an error.
422+
"""Wait until the receiver is ready with a message or an error.
423423
424-
Once a call to `ready()` has finished, the value should be read with
424+
Once a call to `ready()` has finished, the message should be read with
425425
a call to `consume()` (`receive()` or iterated over). The receiver will
426426
remain ready (this method will return immediately) until it is
427427
consumed.
@@ -447,10 +447,10 @@ async def ready(self) -> bool:
447447
# pylint: enable=protected-access
448448

449449
def consume(self) -> _T:
450-
"""Return the latest value once `ready` is complete.
450+
"""Return the latest message once `ready` is complete.
451451
452452
Returns:
453-
The next value that was received.
453+
The next message that was received.
454454
455455
Raises:
456456
ReceiverStoppedError: If there is some problem with the receiver.

src/frequenz/channels/_exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
channel = Anycast[int](name="test-channel")
5151
receiver = channel.new_receiver()
5252
53-
async for value in receiver:
54-
print(value)
53+
async for message in receiver:
54+
print(message)
5555
try:
5656
await receiver.receive()
5757
except ReceiverStoppedError as error:

src/frequenz/channels/_merge.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
receiver1 = channel1.new_receiver()
1818
receiver2 = channel2.new_receiver()
1919
20-
async for value in merge(receiver1, receiver2):
21-
print(value)
20+
async for message in merge(receiver1, receiver2):
21+
print(message)
2222
```
2323
2424
If the first message comes from `channel2` and the second message from `channel1`, the
@@ -135,9 +135,9 @@ async def stop(self) -> None:
135135
self._pending = set()
136136

137137
async def ready(self) -> bool:
138-
"""Wait until the receiver is ready with a value or an error.
138+
"""Wait until the receiver is ready with a message or an error.
139139
140-
Once a call to `ready()` has finished, the value should be read with
140+
Once a call to `ready()` has finished, the message should be read with
141141
a call to `consume()` (`receive()` or iterated over). The receiver will
142142
remain ready (this method will return immediately) until it is
143143
consumed.
@@ -171,10 +171,10 @@ async def ready(self) -> bool:
171171
)
172172

173173
def consume(self) -> _T:
174-
"""Return the latest value once `ready` is complete.
174+
"""Return the latest message once `ready` is complete.
175175
176176
Returns:
177-
The next value that was received.
177+
The next message that was received.
178178
179179
Raises:
180180
ReceiverStoppedError: If the receiver stopped producing messages.

0 commit comments

Comments
 (0)