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
| Trait | Use Case |
|---|---|
RunnableChild | CPU-bound, quick tasks |
AsyncRunnableChild | I/O-bound, network, LLM calls |
Required Methods§
Sourcefn 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,
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 successChildResult::Err(error)on failureChildResult::Abortedif interrupted by signal
§Contract
- Should update status to
Runningat start - Should update status to
IdleorCompletedon success - Should check for cancellation using
tokio::select!or similar