-
Notifications
You must be signed in to change notification settings - Fork 146
ostree: Use indicatif + async for lock wait #1536
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1 +1,29 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| use std::{future::Future, time::Duration}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// Call an async task function, and write a message to stdout | ||||||||||||||||||||||||||||||||||||||||||||||
| /// with an automatic spinner to show that we're not blocked. | ||||||||||||||||||||||||||||||||||||||||||||||
| /// Note that generally the called function should not output | ||||||||||||||||||||||||||||||||||||||||||||||
| /// anything to stdout as this will interfere with the spinner. | ||||||||||||||||||||||||||||||||||||||||||||||
| pub(crate) async fn async_task_with_spinner<F, T>(msg: &str, f: F) -> T | ||||||||||||||||||||||||||||||||||||||||||||||
| where | ||||||||||||||||||||||||||||||||||||||||||||||
| F: Future<Output = T>, | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| let pb = indicatif::ProgressBar::new_spinner(); | ||||||||||||||||||||||||||||||||||||||||||||||
| let style = indicatif::ProgressStyle::default_bar(); | ||||||||||||||||||||||||||||||||||||||||||||||
| pb.set_style(style.template("{spinner} {msg}").unwrap()); | ||||||||||||||||||||||||||||||||||||||||||||||
| pb.set_message(msg.to_string()); | ||||||||||||||||||||||||||||||||||||||||||||||
| pb.enable_steady_tick(Duration::from_millis(150)); | ||||||||||||||||||||||||||||||||||||||||||||||
| let r = f.await; | ||||||||||||||||||||||||||||||||||||||||||||||
| pb.finish_and_clear(); | ||||||||||||||||||||||||||||||||||||||||||||||
| r | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the future
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow that's kinda wild that it noticed that. While I guess it's true... if we panic it's not like the fact that the spinner isn't cleared is the most jarring UX from the whole thing 😆 |
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #[cfg(test)] | ||||||||||||||||||||||||||||||||||||||||||||||
| mod tests { | ||||||||||||||||||||||||||||||||||||||||||||||
| use super::*; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #[tokio::test] | ||||||||||||||||||||||||||||||||||||||||||||||
| async fn test_spinner() { | ||||||||||||||||||||||||||||||||||||||||||||||
| async_task_with_spinner("Testing...", tokio::time::sleep(Duration::from_secs(5))).await | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to construct the
SysrootLockis duplicated. You can refactor this to avoid repetition by handling the case where the lock isn't immediately available, and then having a single point ofSysrootLockcreation. This will make the code more maintainable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but not worth blocking over