pub struct Detached<Input, Error, Context, NodeType = (), NodeOutput = (), NodeError = ()> { /* private fields */ }Expand description
Detached executes a node asynchronously and independently of the main flow.
The node is executed in a detached task using the SpawnAsync
context trait and any result or error from the detached node is ignored.
This flow is useful for side-effect operations such as logging, analytics, or background triggers that should not block or influence the main execution path.
§Type Parameters
Input: The type of data accepted and produced by this flow.Error: The type of error emitted by this flow.Context: The type of context used during execution.
§Examples
use node_flow::node::{Node, NodeOutput};
use node_flow::context::{SpawnAsync, Fork};
use node_flow::flows::Detached;
use std::future::Future;
#[derive(Clone)]
struct PrintNode;
struct ExampleCtx;
impl Fork for ExampleCtx // ...
impl SpawnAsync for ExampleCtx // ...
impl<Ctx: Send> Node<u8, NodeOutput<()>, (), Ctx> for PrintNode {
async fn run(&mut self, input: u8, _: &mut Ctx) -> Result<NodeOutput<()>, ()> {
println!("Running detached task with input: {input}");
Ok(NodeOutput::Ok(()))
}
}
async fn main() {
let mut detached = Detached::<u8, (), _>::new(PrintNode);
let mut ctx = ExampleCtx;
let result = detached.run(7, &mut ctx).await;
assert_eq!(result, Ok(NodeOutput::Ok(7)));
}Implementations§
Source§impl<Input, Error, Context> Detached<Input, Error, Context>
impl<Input, Error, Context> Detached<Input, Error, Context>
Sourcepub fn new<NodeType, NodeOutput, NodeError>(
node: NodeType,
) -> Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
pub fn new<NodeType, NodeOutput, NodeError>( node: NodeType, ) -> Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
Creates a new Detached flow by wrapping the given node.
See also Detached.
§Examples
use node_flow::flows::Detached;
use node_flow::node::{Node, NodeOutput};
#[derive(Clone)]
struct BackgroundTask;
impl<Ctx: Send> Node<(), NodeOutput<()>, (), Ctx> for BackgroundTask // ...
let detached = Detached::<(), (), Ctx>::new(BackgroundTask);Trait Implementations§
Source§impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Clone for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Clone for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
Source§impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Debug for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>where
NodeType: Debug,
impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Debug for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>where
NodeType: Debug,
Source§impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Node<Input, NodeOutput<Input>, Error, Context> for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Node<Input, NodeOutput<Input>, Error, Context> for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
Source§fn run(
&mut self,
input: Input,
context: &mut Context,
) -> impl Future<Output = Result<NodeOutput<Input>, Error>> + Send
fn run( &mut self, input: Input, context: &mut Context, ) -> impl Future<Output = Result<NodeOutput<Input>, Error>> + Send
Runs the node. Read more
Source§fn describe(&self) -> Description
fn describe(&self) -> Description
Describes this node, its type signature and other specifics. Read more
Auto Trait Implementations§
impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Freeze for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
impl<Input, Error, Context, NodeType, NodeOutput, NodeError> RefUnwindSafe for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>where
NodeType: RefUnwindSafe,
impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Send for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Sync for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
impl<Input, Error, Context, NodeType, NodeOutput, NodeError> Unpin for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>
impl<Input, Error, Context, NodeType, NodeOutput, NodeError> UnwindSafe for Detached<Input, Error, Context, NodeType, NodeOutput, NodeError>where
NodeType: RefUnwindSafe,
Blanket Implementations§
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
Source§impl<Input, Output, Error, Context, T> BoxedNode<Input, Output, Error, Context> for Twhere
T: Node<Input, Output, Error, Context>,
impl<Input, Output, Error, Context, T> BoxedNode<Input, Output, Error, Context> for Twhere
T: Node<Input, Output, Error, Context>,
Source§fn run_boxed<'life0, 'life1, 'async_trait>(
&'life0 mut self,
input: Input,
context: &'life1 mut Context,
) -> Pin<Box<dyn Future<Output = Result<Output, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Input: 'async_trait,
Output: 'async_trait,
Error: 'async_trait,
T: 'async_trait,
fn run_boxed<'life0, 'life1, 'async_trait>(
&'life0 mut self,
input: Input,
context: &'life1 mut Context,
) -> Pin<Box<dyn Future<Output = Result<Output, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Input: 'async_trait,
Output: 'async_trait,
Error: 'async_trait,
T: 'async_trait,
Available on crate feature
boxed_node only.Runs the node. Read more
Source§fn describe(&self) -> Description
fn describe(&self) -> Description
Available on crate feature
boxed_node only.Describes this node, its type signature and other specifics. Read more