Skip to main content

AsyncRunnableChild

Trait AsyncRunnableChild 

Source
pub trait AsyncRunnableChild: Child {
    // Required method
    fn run<'life0, 'async_trait>(
        &'life0 mut self,
        input: Value,
    ) -> Pin<Box<dyn Future<Output = ChildResult> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Async version of RunnableChild.

Use this trait for children that perform async I/O operations such as LLM API calls, network requests, or file I/O.

§Example

use orcs_component::{AsyncRunnableChild, ChildResult, Child};
use async_trait::async_trait;
use serde_json::Value;

struct LlmWorker {
    // ...
}

#[async_trait]
impl AsyncRunnableChild for LlmWorker {
    async fn run(&mut self, input: Value) -> ChildResult {
        // Async LLM call
        let response = self.client.complete(&input).await?;
        ChildResult::Ok(response)
    }
}

§When to Use

TraitUse Case
RunnableChildCPU-bound, quick tasks
AsyncRunnableChildI/O-bound, network, LLM calls

Required Methods§

Source

fn run<'life0, 'async_trait>( &'life0 mut self, input: Value, ) -> Pin<Box<dyn Future<Output = ChildResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute work with the given input (asynchronous).

§Arguments
  • input - Input data for the work (JSON value)
§Returns
  • ChildResult::Ok(value) on success
  • ChildResult::Err(error) on failure
  • ChildResult::Aborted if interrupted by signal
§Contract
  • Should update status to Running at start
  • Should update status to Idle or Completed on success
  • Should check for cancellation using tokio::select! or similar

Implementors§