Module radiorust::flow

source ·
Expand description

Data flow between signal processing blocks

Overview

This module provides an extension to the broadcast_bp channel. Like broadcast_bp, a type argument T is used to select the type of the passed values. However, only types which implement the Message trait can be used by this module.

Opposed to broadcast_bp, this module allows Receivers to be (re-)connected to different Senders after creation and use. For that, each Sender has an associated SenderConnector and each Receiver has an associated ReceiverConnector. The connectors provide methods to (re-)connect their associated Senders and Receivers.

Moreover, two traits Producer and Consumer are provided, which describe data types that produce or consume data using a background task and which contain a SenderConnector or ReceiverConnector, respectively, such that it’s possible to connect Producers and Consumers with each other.

Upon disconnection, a special value is optionally inserted into the stream of received values. This value is determined by the Message::disconnection method.

Implementing a Producer or Consumer

Upon creation, Producers use the new_sender function to create a pair consisting of a Sender and a SenderConnector. The Sender is passed to a background task while the SenderConnector is stored and accessible through the Producer::sender_connector method.

Consumers use the new_receiver function upon creation to create a pair of a Receiver and a ReceiverConnector. The Receiver is passed to a background task while the ReceiverConnector is stored and accessible through the Consumer::receiver_connector method.

Refer to the source code of the Nop block for an example.

Buffering and Congestion

Connecting a Producer to more than one Consumer at the same time will stall all involved blocks if one of the Consumers is stalled; i.e. all Consumers must process the data in order for the Producer to be able to send further data.

There is a buffer capacity of 1 for each Sender/Producer. Because of this, longer chains may lead to a significant buffer volume.

The blocks module uses the Buffer block for tweaking buffering behavior, including dropping data in case of congestion and countermeasures against latency.

Re-exports

pub use crate::sync::broadcast_bp::channel as new_sender;
pub use crate::sync::broadcast_bp::Enlister as SenderConnector;
pub use crate::sync::broadcast_bp::RecvError;
pub use crate::sync::broadcast_bp::Reservation;
pub use crate::sync::broadcast_bp::RsrvError;
pub use crate::sync::broadcast_bp::SendError;
pub use crate::sync::broadcast_bp::Sender;

Structs

Receiver that can be dynamically connected to a Sender
Handle to connect a Receiver to a Sender
Wrapper implementing Message, which doesn’t provide a value that indicates disconnection

Traits

Type which contains a ReceiverConnector and can be connected to a Producer
Types that can be used as message from Sender to Receiver
Type which contains a SenderConnector and can be connected to a Consumer

Functions

Create a Receiver with an associated ReceiverConnector