Skip to content

Commit bae785e

Browse files
committed
fix(tui/auto-drive): schedule restarts without tokio
1 parent 1e8dbfe commit bae785e

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

code-rs/tui/src/chatwidget.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17584,12 +17584,21 @@ fi\n\
1758417584

1758517585
fn auto_schedule_restart_event(&self, token: u64, attempt: u32, delay: Duration) {
1758617586
let tx = self.app_event_tx.clone();
17587-
tokio::spawn(async move {
17588-
if !delay.is_zero() {
17589-
tokio::time::sleep(delay).await;
17590-
}
17591-
tx.send(AppEvent::AutoCoordinatorRestart { token, attempt });
17592-
});
17587+
if let Ok(handle) = tokio::runtime::Handle::try_current() {
17588+
handle.spawn(async move {
17589+
if !delay.is_zero() {
17590+
tokio::time::sleep(delay).await;
17591+
}
17592+
tx.send(AppEvent::AutoCoordinatorRestart { token, attempt });
17593+
});
17594+
} else {
17595+
std::thread::spawn(move || {
17596+
if !delay.is_zero() {
17597+
std::thread::sleep(delay);
17598+
}
17599+
tx.send(AppEvent::AutoCoordinatorRestart { token, attempt });
17600+
});
17601+
}
1759317602
}
1759417603

1759517604
fn auto_pause_for_transient_failure(&mut self, message: String) {

0 commit comments

Comments
 (0)