Skip to content

Commit

Permalink
feat(hydroflow_plus): add API for external network inputs (#1449)
Browse files Browse the repository at this point in the history
This is a key step towards being able to unit-test HF+ graphs, by being
able to have controlled inputs. Outputs next.
  • Loading branch information
shadaj committed Sep 11, 2024
1 parent 51a3f55 commit 8a80931
Show file tree
Hide file tree
Showing 23 changed files with 1,062 additions and 345 deletions.
18 changes: 18 additions & 0 deletions hydro_deploy/core/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,29 @@ impl Deployment {
Ok(())
}

/// Runs `start()`, waits for the trigger future, then runs `stop()`.
/// This is useful if you need to initiate external network connections between
/// `deploy()` and `start()`.
pub async fn start_until(&mut self, trigger: impl Future<Output = ()>) -> Result<()> {
// TODO(mingwei): should `trigger` interrupt `deploy()` and `start()`? If so make sure shutdown works as expected.
self.start().await?;
trigger.await;
self.stop().await?;
Ok(())
}

/// Runs `deploy()`, and `start()`, waits for CTRL+C, then runs `stop()`.
pub async fn run_ctrl_c(&mut self) -> Result<()> {
self.run_until(tokio::signal::ctrl_c().map(|_| ())).await
}

/// Runs `start()`, waits for CTRL+C, then runs `stop()`.
/// This is useful if you need to initiate external network connections between
/// `deploy()` and `start()`.
pub async fn start_ctrl_c(&mut self) -> Result<()> {
self.start_until(tokio::signal::ctrl_c().map(|_| ())).await
}

pub async fn deploy(&mut self) -> Result<()> {
self.services.retain(|weak| weak.strong_count() > 0);

Expand Down
Loading

0 comments on commit 8a80931

Please sign in to comment.