use crate::application::Engine;
use crate::application::{Executor, ExecutorError};
use crate::domain::{Asset, Graph};
use futures::future::try_join_all;
pub struct RunDownstream<E> {
engine: Engine,
executor: E,
}
impl<E: Executor> RunDownstream<E> {
pub fn new(graph: Graph, executor: E) -> Self {
Self { engine: Engine::new(graph), executor }
}
pub async fn execute(&self, start: &Asset) -> Result<(), ExecutorError> {
self.executor.run(start).await?;
for wave in self.engine.downstream_levels(start) {
let futs: Vec<_> = wave.iter().map(|asset| self.executor.run(asset)).collect();
try_join_all(futs).await?;
}
Ok(())
}
pub fn plan(&self, start: &Asset) -> Vec<Asset> {
let mut plan = vec![start.clone()];
plan.extend(self.engine.propagate_downstream(start));
plan
}
}