synaptic_tools/
parallel_executor.rs1use serde_json::Value;
2use synaptic_core::SynapseError;
3
4use crate::ToolRegistry;
5
6pub struct ParallelToolExecutor {
8 registry: ToolRegistry,
9}
10
11impl ParallelToolExecutor {
12 pub fn new(registry: ToolRegistry) -> Self {
14 Self { registry }
15 }
16
17 pub async fn execute_all(
22 &self,
23 calls: Vec<(String, Value)>,
24 ) -> Vec<Result<Value, SynapseError>> {
25 let futures: Vec<_> = calls
26 .into_iter()
27 .map(|(name, args)| {
28 let registry = self.registry.clone();
29 async move {
30 let tool = registry
31 .get(&name)
32 .ok_or(SynapseError::ToolNotFound(name))?;
33 tool.call(args).await
34 }
35 })
36 .collect();
37
38 futures::future::join_all(futures).await
39 }
40}