experimental
frequenz.channels.experimental ¤
Experimental channel primitives.
Warning
This package contains experimental channel primitives that are not yet considered stable. They are subject to change without notice, including removal, even in minor updates.
Classes¤
frequenz.channels.experimental.Pipe ¤
Bases: Generic[ChannelMessageT]
A pipe between two channels.
The Pipe
class takes a receiver and a sender and creates a pipe between them
by forwarding all the messages received by the receiver to the sender.
Example
from frequenz.channels import Broadcast, Pipe
channel1: Broadcast[int] = Broadcast(name="channel1")
channel2: Broadcast[int] = Broadcast(name="channel2")
receiver_chan1 = channel1.new_receiver()
sender_chan2 = channel2.new_sender()
async with Pipe(channel2.new_receiver(), channel1.new_sender()):
await sender_chan2.send(10)
assert await receiver_chan1.receive() == 10
Source code in frequenz/channels/experimental/_pipe.py
Functions¤
__aenter__
async
¤
__aenter__() -> Pipe[ChannelMessageT]
__aexit__
async
¤
__aexit__(
_exc_type: Type[BaseException],
_exc: BaseException,
_tb: Any,
) -> None
__init__ ¤
__init__(
receiver: Receiver[ChannelMessageT],
sender: Sender[ChannelMessageT],
) -> None
Create a new pipe between two channels.
PARAMETER | DESCRIPTION |
---|---|
receiver |
The receiver channel.
TYPE:
|
sender |
The sender channel.
TYPE:
|
Source code in frequenz/channels/experimental/_pipe.py
start
async
¤
frequenz.channels.experimental.RelaySender ¤
Bases: Generic[SenderMessageT_contra]
, Sender[SenderMessageT_contra]
A Sender for sending messages to multiple senders.
The RelaySender
class takes multiple senders and forwards all the messages sent to
it, to the senders it was created with.
Example
from frequenz.channels import Broadcast
from frequenz.channels.experimental import RelaySender
channel1: Broadcast[int] = Broadcast(name="channel1")
channel2: Broadcast[int] = Broadcast(name="channel2")
receiver1 = channel1.new_receiver()
receiver2 = channel2.new_receiver()
tee_sender = RelaySender(channel1.new_sender(), channel2.new_sender())
await tee_sender.send(5)
assert await receiver1.receive() == 5
assert await receiver2.receive() == 5
Source code in frequenz/channels/experimental/_relay_sender.py
Functions¤
__init__ ¤
__init__(*senders: Sender[SenderMessageT_contra]) -> None
Create a new RelaySender.
PARAMETER | DESCRIPTION |
---|---|
*senders |
The senders to send messages to.
TYPE:
|
send
async
¤
send(message: SenderMessageT_contra) -> None
Send a message.
PARAMETER | DESCRIPTION |
---|---|
message |
The message to be sent.
TYPE:
|