pub fn eval_async<'life0, 'life1, 'async_recursion, D>(
node: &'life0 Node,
ctx: Value,
dispatcher: &'life1 D,
) -> Pin<Box<dyn Future<Output = Result<Value, EvalError>> + Send + 'async_recursion>>where
D: AsyncDispatcher + ?Sized + 'async_recursion,
'life0: 'async_recursion,
'life1: 'async_recursion,Expand description
Evaluate a Node against a context value asynchronously,
using the given async dispatcher for Step resolution.
eval (sync) と同型 logic、 dispatch を .await に置き換え。 Seq / Branch
は recursive async fn (= async_recursion macro で Pin<Box> wrap)。
§Quick start
use async_trait::async_trait;
use mlua_flow_ir::{eval_async, AsyncDispatcher, EvalError, Expr, Node};
use serde_json::{json, Value};
struct Fixture;
#[async_trait]
impl AsyncDispatcher for Fixture {
async fn dispatch(&self, _r: &str, input: Value) -> Result<Value, EvalError> {
if let Value::String(s) = input {
Ok(Value::String(s.to_uppercase()))
} else {
Ok(input)
}
}
}
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let node = Node::Step {
ref_: "up".into(),
in_: Expr::Path { at: "$.input".into() },
out: Expr::Path { at: "$.output".into() },
};
let out = eval_async(&node, json!({ "input": "hello" }), &Fixture).await.unwrap();
assert_eq!(out, json!({ "input": "hello", "output": "HELLO" }));
});