Skip to main content

node_fn

Function node_fn 

Source
pub fn node_fn<S, F, Fut>(f: F) -> impl Node<S>
where S: GraphState, F: Fn(&S, &RunnableConfig) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<NodeOutput>> + Send + 'static,
Expand description

Create a node from an async function.

This is a convenience function to create nodes from closures or async functions without implementing the Node trait manually.

§Examples

ⓘ
use regula_core::{node_fn, NodeOutput, Result};

let my_node = node_fn(|state: &MyState, config: &RunnableConfig| async move {
    Ok(NodeOutput::update(serde_json::json!({
        "counter": state.counter + 1
    })))
});