Skip to content

Commit

Permalink
Merge pull request #2096 from itowlson/watch-do-not-run-until-a-build…
Browse files Browse the repository at this point in the history
…-has-succeeded

Watch should not serve until there is a build
  • Loading branch information
itowlson authored Nov 14, 2023
2 parents 3d9d266 + 28ddd7e commit d373025
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/commands/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl WatchCommand {
spin_bin: spin_bin.clone(),
manifest: manifest_file.clone(),
clear_screen: self.clear,
has_ever_built: false,
watched_changes: source_code_rx,
uppificator_pauser: pause_tx,
};
Expand Down
13 changes: 10 additions & 3 deletions src/commands/watch/buildifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ pub(crate) struct Buildifier {
pub spin_bin: PathBuf,
pub manifest: PathBuf,
pub clear_screen: bool,
pub has_ever_built: bool,
pub watched_changes: tokio::sync::watch::Receiver<Uuid>, // TODO: refine which component(s) a change affects
pub uppificator_pauser: tokio::sync::mpsc::Sender<Pause>,
}

impl Buildifier {
#[allow(clippy::collapsible_if)]
pub(crate) async fn run(&mut self) {
// Other components may close channels as part of shutdown, so if any channels
// fail, just exit the loop and fall out normally.
Expand All @@ -26,10 +28,15 @@ impl Buildifier {
break;
}

_ = self.build_once().await;
let build_result = self.build_once().await;
if !self.has_ever_built {
self.has_ever_built = matches!(build_result, Ok(true));
}

if self.uppificator_pauser.send(Pause::Unpause).await.is_err() {
break;
if self.has_ever_built {
if self.uppificator_pauser.send(Pause::Unpause).await.is_err() {
break;
}
}

if self.watched_changes.changed().await.is_err() {
Expand Down

0 comments on commit d373025

Please sign in to comment.