Skip to content

Commit 30ddc9c

Browse files
committed
PR feedback
1 parent a990b47 commit 30ddc9c

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

crates/turborepo-lib/src/run/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ pub struct Run {
7474
should_print_prelude: bool,
7575
}
7676

77-
type UIResult = Result<Option<(UISender, JoinHandle<Result<(), turborepo_ui::Error>>)>, Error>;
78-
type WuiResult = Result<Option<(WebUISender, JoinHandle<Result<(), turborepo_ui::Error>>)>, Error>;
79-
type TuiResult = Result<Option<(TuiSender, JoinHandle<Result<(), turborepo_ui::Error>>)>, Error>;
77+
type UIResult<T> = Result<Option<(T, JoinHandle<Result<(), turborepo_ui::Error>>)>, Error>;
78+
79+
type WuiResult = UIResult<WebUISender>;
80+
type TuiResult = UIResult<TuiSender>;
8081

8182
impl Run {
8283
fn has_persistent_tasks(&self) -> bool {
@@ -210,7 +211,7 @@ impl Run {
210211
&& tui::terminal_big_enough()?)
211212
}
212213

213-
pub fn start_ui(&self) -> UIResult {
214+
pub fn start_ui(&self) -> UIResult<UISender> {
214215
match self.opts.run_opts.ui_mode {
215216
UIMode::Tui => self
216217
.start_terminal_ui()

crates/turborepo-ui/src/wui/server.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct Task {
2222
}
2323

2424
struct CurrentRun<'a> {
25-
state: &'a Arc<Mutex<RefCell<WebUIState>>>,
25+
state: &'a SharedState,
2626
}
2727

2828
#[Object]
@@ -42,12 +42,17 @@ impl<'a> CurrentRun<'a> {
4242
}
4343
}
4444

45+
/// We keep the state in a `Arc<Mutex<RefCell<T>>>` so both `Subscriber` and
46+
/// `Query` can access it, with `Subscriber` mutating it and `Query` only
47+
/// reading it.
48+
type SharedState = Arc<Mutex<RefCell<WebUIState>>>;
49+
4550
pub struct Query {
46-
state: Arc<Mutex<RefCell<WebUIState>>>,
51+
state: SharedState,
4752
}
4853

4954
impl Query {
50-
pub fn new(state: Arc<Mutex<RefCell<WebUIState>>>) -> Self {
55+
pub fn new(state: SharedState) -> Self {
5156
Self { state }
5257
}
5358
}
@@ -80,7 +85,7 @@ pub async fn start_server(
8085
Ok(())
8186
}
8287

83-
pub(crate) async fn run_server(state: Arc<Mutex<RefCell<WebUIState>>>) -> Result<(), crate::Error> {
88+
pub(crate) async fn run_server(state: SharedState) -> Result<(), crate::Error> {
8489
let cors = CorsLayer::new()
8590
// allow `GET` and `POST` when accessing the resource
8691
.allow_methods([Method::GET, Method::POST])

0 commit comments

Comments
 (0)