File tree Expand file tree Collapse file tree 13 files changed +278
-0
lines changed Expand file tree Collapse file tree 13 files changed +278
-0
lines changed Original file line number Diff line number Diff line change 11* [ Quick Start] ( quick-start.md )
22* [ Installation] ( installation.md )
3+ * [ Channels] ( channels/ )
4+ * [ Sending] ( sending.md )
5+ * [ Receiving] ( receiving/ )
6+ * [ Error Handling] ( error-handling.md )
7+ * [ Utilities] ( utilities/ )
Original file line number Diff line number Diff line change 1+ # Anycast
2+
3+ ::: frequenz.channels._ anycast.Anycast
4+ options:
5+ inherited_members: [ ]
6+ members: [ ]
7+ show_bases: false
8+ show_root_heading: false
9+ show_root_toc_entry: false
10+ show_source: false
Original file line number Diff line number Diff line change 1+ # Broadcast
2+
3+ ::: frequenz.channels._ broadcast.Broadcast
4+ options:
5+ inherited_members: [ ]
6+ members: [ ]
7+ show_bases: false
8+ show_root_heading: false
9+ show_root_toc_entry: false
10+ show_source: false
Original file line number Diff line number Diff line change 1+ # Channels
2+
3+ A channel is a communication mechanism that allows data (messages) to be
4+ transmitted between different coroutines. It consists of
5+ [ senders] ( ../sending.md ) , which send messages, and
6+ [ receivers] ( ../receiving/index.md ) , which receive those messages. The channel itself
7+ acts as a conduit for these messages.
8+
9+ Conceptually, a channel looks like this:
10+
11+ <center >
12+ ``` bob
13+ .---------. Message .----------. Message .-----------.
14+ | Sender +------------>| Channel +------------>| Receiver |
15+ '---------' '----------' '-----------'
16+ ```
17+ </center >
18+
19+ Besides this simple model, there are many variations of channels depending on
20+ various factors:
21+
22+ * How many senders and receivers can a channel have?
23+
24+ * Do all receivers receive all messages from all senders?
25+
26+ * How many messages can a channel hold (buffered), or can it hold any messages
27+ at all (unbuffered)?
28+
29+ * What happens if a sender tries to send a message to a full channel?
30+
31+ * Does the send operation block until the channel has space again?
32+ * Does it fail?
33+ * Does it silently drop the message?
34+
35+ Because these questions can have many answers, there are different types of
36+ channels. Frequenz Channels offers a few of them:
37+
38+ * [ Anycast] ( anycast.md )
39+ * [ Broadcast] ( broadcast.md )
40+
41+ More might be added in the future, and you can also create your own.
Original file line number Diff line number Diff line change 1+ # Error Handling
2+
3+ ::: frequenz.channels._ exceptions
4+ options:
5+ inherited_members: [ ]
6+ members: [ ]
7+ show_bases: false
8+ show_root_heading: false
9+ show_root_toc_entry: false
10+ show_source: false
Original file line number Diff line number Diff line change 1+ # Receiving
2+
3+ ::: frequenz.channels._ receiver
4+ options:
5+ inherited_members: [ ]
6+ members: [ ]
7+ show_bases: false
8+ show_root_heading: false
9+ show_root_toc_entry: false
10+ show_source: false
Original file line number Diff line number Diff line change 1+ # Multiple Sources
2+
3+ If you need to receive values from multiple sources it can be complicated, as
4+ you probably want to get the first message of each receiver as soon as it is
5+ available. A naive approach like this will not work:
6+
7+ ``` python
8+ receiver1: Receiver[int ] = channel1.new_receiver()
9+ receiver2: Receiver[int ] = channel2.new_receiver()
10+
11+ msg = await receiver1.receive()
12+ print (f " Received from channel1: { msg} " )
13+
14+ msg = await receiver2.receive()
15+ print (f " Received from channel2: { msg} " )
16+ ```
17+
18+ The problem is that if the first message is not available in ` channel1 ` but in
19+ ` channel2 ` , the program will be blocked until a message is available in
20+ ` channel1 ` , but you probably want to receive the first message from ` channel2 `
21+ as soon as it is available.
22+
23+ Frequenz Channels provides two tools to solve this issue:
24+ [ ` merge() ` ] [ frequenz.channels.merge ] and
25+ [ ` select() ` ] [ frequenz.channels.select ] .
Original file line number Diff line number Diff line change 1+ # Merging
2+
3+ ::: frequenz.channels._ merge
4+ options:
5+ inherited_members: [ ]
6+ members: [ ]
7+ show_bases: false
8+ show_root_heading: false
9+ show_root_toc_entry: false
10+ show_source: false
Original file line number Diff line number Diff line change 1+ # Selecting
2+
3+ ::: frequenz.channels._ select
4+ options:
5+ inherited_members: [ ]
6+ members: [ ]
7+ show_bases: false
8+ show_root_heading: false
9+ show_root_toc_entry: false
10+ show_source: false
11+
Original file line number Diff line number Diff line change 1+ # Sending
2+
3+ ::: frequenz.channels._ sender
4+ options:
5+ inherited_members: [ ]
6+ members: [ ]
7+ show_bases: false
8+ show_root_heading: false
9+ show_root_toc_entry: false
10+ show_source: false
You can’t perform that action at this time.
0 commit comments