Struct fbp::fbp_wait_for_payload::WaitForPayloadNode[][src]

pub struct WaitForPayloadNode {
    pub wait_for_payload: AsyncState,
    pub payload: ThreadSafeOptionType<String>,
    // some fields omitted
}
Expand description

This can be useful when wanting to get the output of a node within that node itself. One make this node a receiver of the node whose output is desired and then have another node call the get_payload async method which will wait for the payload to arrive.

/// # Example

Basic usage:

use async_trait::async_trait;
use std::ops::{Deref};
use serde::{Deserialize, Serialize};

use fbp::fbp_iidmessage::*;
use fbp::fbp_node_context::*;
use fbp::fbp_node_trait::*;
use fbp::fbp_wait_for_payload::*;
use fbp::fbp_node_error::*;

#[derive(Clone, Serialize, Deserialize)]
    pub struct PassthroughNode {
        data: Box<FBPNodeContext>,
    }

    impl PassthroughNode {
        #[allow(dead_code)]
        pub fn new() -> Self {
            let result = PassthroughNode {
                data: Box::new(FBPNodeContext::new("PassthroughNode")),
            };

            result.node_data().set_node_is_configured(true);
            result.clone().start();
            result
        }
    }

    #[async_trait]
    impl FBPNodeTrait for PassthroughNode {
        fn node_data_clone(&self) -> FBPNodeContext {
            self.data.deref().clone()
        }

        fn node_data(&self) -> &FBPNodeContext {
            &self.data
        }

        fn node_data_mut(&mut self) -> &mut FBPNodeContext {
            &mut self.data
        }

        fn process_message(
            &mut self,
            msg: IIDMessage,
        ) -> std::result::Result<IIDMessage, NodeError> {

            Ok(msg.clone())
        }
    }

    let mut pt_node = PassthroughNode::new();
    let mut wait_node = WaitForPayloadNode::new();

    pt_node.node_data_mut().add_receiver(wait_node.node_data_mut(), None);

    let a_msg = IIDMessage::new(MessageType::Data, Some("This is a payload".to_string()));
    pt_node.node_data().post_msg(a_msg);
    let mut rt = tokio::runtime::Builder::new()
            .enable_all()
            .build()
            .unwrap();

    let mut payload: String = String::new();

     rt.block_on(async {
        payload = wait_node.get_payload().await;
    });

Fields

wait_for_payload: AsyncStatepayload: ThreadSafeOptionType<String>

Implementations

Create a new WaitForPayloadNode.

This node wil wait on a payload that is sent to it as an IIDMessage.

Get the payload sent to this node. This is an async method that will wait for an IIDMesssage to be sent to this node and will return the the payload of that message when it arrives.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Return a reference to the FBPNodeContext Read more

Return a mutable reference to an FBPNodeContext Read more

Provide the processing for this node. Read more

Return is an FBP node is fully configured and can process IIDMessages Read more

Block waiting on node to be configured Read more

Process an incoming IIDMessage Read more

Process an IIDMessage that is an Config message Read more

Process an IIDMessage that is a Process message Read more

Run the message loop for an FBP node. Read more

Tell the FBP Node to stop its processing loop Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.