ai_agent/utils/
sequential.rs1use std::future::Future;
5use std::pin::Pin;
6
7pub async fn sequential<T, R, F>(items: T, mut f: F) -> Vec<R>
9where
10 T: IntoIterator<Item = R>,
11 F: FnMut(R) -> Pin<Box<dyn Future<Output = R> + Send>>,
12 R: std::fmt::Debug,
13{
14 let mut results = Vec::new();
15
16 for item in items {
17 let result = f(item).await;
18 results.push(result);
19 }
20
21 results
22}
23
24pub async fn sequential_with_index<T, R, F>(items: T, mut f: F) -> Vec<R>
26where
27 T: IntoIterator<Item = R>,
28 F: FnMut(R, usize) -> Pin<Box<dyn Future<Output = R> + Send>>,
29 R: std::fmt::Debug,
30{
31 let mut results = Vec::new();
32
33 for (index, item) in items.into_iter().enumerate() {
34 let result = f(item, index).await;
35 results.push(result);
36 }
37
38 results
39}