Skip to content

Commit 7426fc9

Browse files
chore(tui): move ticks to dedicated task
1 parent d9d9262 commit 7426fc9

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

crates/turborepo-ui/src/tui/app.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use tokio::{
1717
};
1818
use tracing::{debug, trace};
1919

20-
const FRAMERATE: Duration = Duration::from_millis(3);
20+
pub const FRAMERATE: Duration = Duration::from_millis(3);
2121
const RESIZE_DEBOUNCE_DELAY: Duration = Duration::from_millis(10);
2222

2323
use super::{
@@ -590,14 +590,7 @@ async fn run_app_inner<B: Backend + std::io::Write>(
590590
let mut resize_debouncer = Debouncer::new(RESIZE_DEBOUNCE_DELAY);
591591
let mut callback = None;
592592
let mut needs_rerender = true;
593-
while let Some(event) = poll(
594-
app.input_options()?,
595-
&mut receiver,
596-
&mut crossterm_rx,
597-
last_render + FRAMERATE,
598-
)
599-
.await
600-
{
593+
while let Some(event) = poll(app.input_options()?, &mut receiver, &mut crossterm_rx).await {
601594
// If we only receive ticks, then there's been no state change so no update
602595
// needed
603596
if !matches!(event, Event::Tick) {
@@ -639,7 +632,6 @@ async fn poll<'a>(
639632
input_options: InputOptions<'a>,
640633
receiver: &mut AppReceiver,
641634
crossterm_rx: &mut mpsc::Receiver<crossterm::event::Event>,
642-
deadline: Instant,
643635
) -> Option<Event> {
644636
let input_closed = crossterm_rx.is_closed();
645637
let input_fut = async {
@@ -660,11 +652,7 @@ async fn poll<'a>(
660652
}
661653
};
662654

663-
match tokio::time::timeout_at(deadline, event_fut).await {
664-
Ok(Some(e)) => Some(e),
665-
Err(_timeout) => Some(Event::Tick),
666-
Ok(None) => None,
667-
}
655+
event_fut.await
668656
}
669657

670658
const MIN_HEIGHT: u16 = 10;

crates/turborepo-ui/src/tui/handle.rs

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::sync::{Arc, Mutex};
33
use tokio::sync::{mpsc, oneshot};
44

55
use super::{
6+
app::FRAMERATE,
67
event::{CacheResult, OutputLogs, PaneSize},
78
Event, TaskResult,
89
};
@@ -33,6 +34,16 @@ impl AppSender {
3334
/// AppReceiver should be passed to `crate::tui::run_app`
3435
pub fn new() -> (Self, AppReceiver) {
3536
let (primary_tx, primary_rx) = mpsc::unbounded_channel();
37+
let tick_sender = primary_tx.clone();
38+
tokio::spawn(async move {
39+
let mut interval = tokio::time::interval(FRAMERATE);
40+
loop {
41+
interval.tick().await;
42+
if tick_sender.send(Event::Tick).is_err() {
43+
break;
44+
}
45+
}
46+
});
3647
(
3748
Self {
3849
primary: primary_tx,

0 commit comments

Comments
 (0)