Skip to content

Commit

Permalink
Only create the Watcher if necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
nfachan committed Feb 14, 2025
1 parent 051dd0b commit 9ba9272
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions crates/maelstrom-test-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,19 +476,24 @@ fn run_app_once<TestCollectorT: TestCollector + Sync>(

std::thread::scope(|scope| {
let result = (|| -> ControlFlow<Result<_>> {
let watcher = Watcher::new(
scope,
log.clone(),
&directories.project,
watch_exclude_paths,
&done,
&files_changed,
);
if extra_options.watch {
if let Err(err) = watcher.watch_for_changes() {
return ControlFlow::Break(Err(err));
}
}
let watcher = if extra_options.watch {
Some({
let watcher = Watcher::new(
scope,
log.clone(),
&directories.project,
watch_exclude_paths,
&done,
&files_changed,
);
if let Err(err) = watcher.watch_for_changes() {
return ControlFlow::Break(Err(err));
}
watcher
})
} else {
None
};

let result = run_app_once_inner(
client,
Expand All @@ -501,19 +506,20 @@ fn run_app_once<TestCollectorT: TestCollector + Sync>(
ui_sender.clone(),
);

if extra_options.watch {
if let Err(err) = client.restart() {
return ControlFlow::Break(Err(err));
}
match watcher {
None => ControlFlow::Break(result),
Some(watcher) => {
if let Err(err) = client.restart() {
return ControlFlow::Break(Err(err));
}

ui_sender.send(UiMessage::UpdateEnqueueStatus(
"waiting for changes...".into(),
));
watcher.wait_for_changes();
ui_sender.send(UiMessage::UpdateEnqueueStatus(
"waiting for changes...".into(),
));
watcher.wait_for_changes();

ControlFlow::Continue(())
} else {
ControlFlow::Break(result)
ControlFlow::Continue(())
}
}
})();

Expand Down

0 comments on commit 9ba9272

Please sign in to comment.