Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(watch): simplify watch data synchronization #9154

Merged
merged 2 commits into from
Sep 17, 2024

Conversation

chris-olszewski
Copy link
Member

Description

Basic view of the futures involved with running watch

  • The events_fut takes events from the package changes watcher and folds them into a ChangedPackages struct. It then triggers a notify.
  • The run_fut loops waiting for a notification and then performing a run.
  • Signal handler watching for SIGINTs

This PR cleans up how packages changes are synchronized between futures:

  • Removes RefCell as Mutex already implies mutually exclusive access the the underlying resource
  • Remove run_fut holding onto the changed packages lock for the entirety of it's run. This allows us to switch from tokio::sync::Mutex to std::sync::Mutex. Which is suggested by the tokio::sync::Mutex docs

Testing Instructions

rustc + 👀 . Quick gut check by running turbo watch and triggering package changes

Copy link

vercel bot commented Sep 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 16, 2024 7:40pm
8 Skipped Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Sep 16, 2024 7:40pm
examples-designsystem-docs ⬜️ Ignored (Inspect) Sep 16, 2024 7:40pm
examples-gatsby-web ⬜️ Ignored (Inspect) Sep 16, 2024 7:40pm
examples-kitchensink-blog ⬜️ Ignored (Inspect) Sep 16, 2024 7:40pm
examples-native-web ⬜️ Ignored (Inspect) Sep 16, 2024 7:40pm
examples-svelte-web ⬜️ Ignored (Inspect) Sep 16, 2024 7:40pm
examples-tailwind-web ⬜️ Ignored (Inspect) Sep 16, 2024 7:40pm
examples-vite-web ⬜️ Ignored (Inspect) Sep 16, 2024 7:40pm

Copy link
Member Author

@chris-olszewski chris-olszewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer's guide

let changed_packages_guard = changed_packages.lock().await;
if !changed_packages_guard.borrow().is_empty() {
let changed_packages = changed_packages_guard.take();
let some_changed_packages = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only acquire the guard in the block so we ensure we release the lock once we take the changed packages. This lets the event_fut make progress while self.execute_run is pending.

(!changed_packages_guard.is_empty())
.then(|| std::mem::take(changed_packages_guard.deref_mut()))
};
if let Some(changed_packages) = some_changed_packages {
self.execute_run(changed_packages).await?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed_packages_guard is still held while run is being executed, this prevents any events from being handled.

@chris-olszewski chris-olszewski marked this pull request as ready for review September 16, 2024 19:45
@chris-olszewski chris-olszewski requested a review from a team as a code owner September 16, 2024 19:45
@chris-olszewski chris-olszewski merged commit ed8ff72 into main Sep 17, 2024
40 checks passed
@chris-olszewski chris-olszewski deleted the olszewski/chore_cleanup_watch branch September 17, 2024 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants