pub struct Delay<T: Message = Any> {
pub input: InputPort<T>,
pub output: OutputPort<T>,
pub delay: DelayType,
}Expand description
A block that passes messages through while delaying them by a fixed or random duration.
§Block Diagram
block-beta
columns 7
Source space:2 Delay space:2 Sink
Source-- "input" -->Delay
Delay-- "output" -->Sink
classDef block height:48px,padding:8px;
classDef hidden visibility:none;
class Delay block
class Source hidden
class Sink hidden
§Sequence Diagram
sequenceDiagram
autonumber
participant BlockA as Another block
participant Delay.input as Delay.input port
participant Delay as Delay block
participant Delay.output as Delay.output port
participant BlockB as Another block
BlockA-->>Delay: Connect
Delay-->>BlockB: Connect
loop Delay process
BlockA->>Delay: Message
Delay->>Delay: Sleep
Delay->>BlockB: Message
end
BlockA-->>Delay: Disconnect
Delay-->>Delay.input: Close
Delay-->>Delay.output: Close
Delay-->>BlockB: Disconnect
§Examples
§Using the block in a system
System::build(|s| {
let stdin = s.read_stdin();
let line_decoder = s.decode_lines();
let delay = Duration::from_secs(1);
let delayer = s.delay_by_fixed::<String>(delay);
let line_encoder = s.encode_lines();
let stdout = s.write_stdout();
s.connect(&stdin.output, &line_decoder.input);
s.connect(&line_decoder.output, &delayer.input);
s.connect(&delayer.output, &line_encoder.input);
s.connect(&line_encoder.output, &stdout.input);
});§Running the block via the CLI
$ protoflow execute Delay fixed=2$ protoflow execute Delay random=1..5Fields§
§input: InputPort<T>The input message stream.
output: OutputPort<T>The output target for the stream being passed through.
delay: DelayTypeA configuration parameter for which type of delay to add.
Implementations§
Source§impl<T: Message> Delay<T>
impl<T: Message> Delay<T>
pub fn new(input: InputPort<T>, output: OutputPort<T>) -> Self
pub fn with_params( input: InputPort<T>, output: OutputPort<T>, delay: Option<DelayType>, ) -> Self
Trait Implementations§
Source§impl<T: Message> Block for Delay<T>
impl<T: Message> Block for Delay<T>
Source§fn execute(&mut self, runtime: &dyn BlockRuntime) -> BlockResult
fn execute(&mut self, runtime: &dyn BlockRuntime) -> BlockResult
Executes this block’s computation.
Source§fn prepare(&mut self, _runtime: &dyn BlockRuntime) -> Result<(), BlockError>
fn prepare(&mut self, _runtime: &dyn BlockRuntime) -> Result<(), BlockError>
Prepares this block for execution. Read more
Source§impl<T: Message> BlockDescriptor for Delay<T>
impl<T: Message> BlockDescriptor for Delay<T>
Source§fn inputs(&self) -> Vec<PortDescriptor>
fn inputs(&self) -> Vec<PortDescriptor>
A description of this block’s input ports.
Source§fn outputs(&self) -> Vec<PortDescriptor>
fn outputs(&self) -> Vec<PortDescriptor>
A description of this block’s output ports.
Source§fn parameters(&self) -> Vec<ParameterDescriptor>
fn parameters(&self) -> Vec<ParameterDescriptor>
A description of this block’s parameters.
Source§fn ports(&self) -> Vec<PortDescriptor>
fn ports(&self) -> Vec<PortDescriptor>
A description of this block’s I/O ports.
Source§impl<T: Message> MaybeLabeled for Delay<T>
impl<T: Message> MaybeLabeled for Delay<T>
Source§impl<T: Message> MaybeNamed for Delay<T>
impl<T: Message> MaybeNamed for Delay<T>
Source§impl<T: Message + FromStr + ToString + 'static> StdioSystem for Delay<T>
impl<T: Message + FromStr + ToString + 'static> StdioSystem for Delay<T>
fn build_system(config: StdioConfig) -> Result<System, StdioError>
Auto Trait Implementations§
impl<T> Freeze for Delay<T>
impl<T = Any> !RefUnwindSafe for Delay<T>
impl<T> Send for Delay<T>
impl<T> Sync for Delay<T>
impl<T> Unpin for Delay<T>where
T: Unpin,
impl<T = Any> !UnwindSafe for Delay<T>
Blanket Implementations§
Source§impl<T> AsBlockDescriptor for Twhere
T: BlockDescriptor,
impl<T> AsBlockDescriptor for Twhere
T: BlockDescriptor,
fn as_block_descriptor(&self) -> &dyn BlockDescriptor
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more