From 6852204277f4ed742df21ca8ec2f886d486bd79b Mon Sep 17 00:00:00 2001 From: faumaray Date: Tue, 27 Oct 2026 09:42:21 +0300 Subject: [PATCH] voelin-gpui: Later::run says what its answer promises The doc said `false` "when the window is gone". The loop that drains the jobs learns that the entity was released only when a job reaches it: the first job sent after the release still answers `true` and is never run, and only the next call is refused (a hotkey or decoder thread that calls run() after the window went and before another job could so believe a job was queued that never ran). The doc says that now ("false once a job has found the window gone", true promises that the job was queued), and a test pins the order: the job after the release is queued and never runs, the one after it is refused. Co-Authored-By: Claude Sonnet 5.5 --- crates/voelin-gpui/src/app.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/voelin-gpui/src/app.rs b/crates/voelin-gpui/src/app.rs index 5c323e1..571634b 100644 --- a/crates/voelin-gpui/src/app.rs +++ b/crates/voelin-gpui/src/app.rs @@ -47,7 +47,11 @@ type Job = Box) + Send>; pub struct Later(UnboundedSender); impl Later { - /// Run `job` on GPUI's thread soon; `false` when the window is gone. + /// Run `job` on GPUI's thread soon. `false` once a job has found the + /// window gone (the entity released): the loop that runs the jobs notices + /// that only when a job reaches it, ends and drops the channel, so the + /// first job sent after the window went answers `true` and is never run. + /// `true` is a promise of nothing more than that the job was queued. pub fn run( &self, job: impl FnOnce(&mut AppState, &mut Context) + Send + 'static, @@ -371,6 +375,21 @@ mod tests { assert_eq!(counters.later_jobs.get(), 1); } + #[gpui::test] + fn a_job_sent_after_the_window_went_is_dropped_and_the_next_one_is_refused( + cx: &mut TestAppContext, + ) { + let (app, _tx, counters) = entity(cx); + let later = app.read_with(cx, |app, _| app.later()); + drop(app); + cx.update(|_| {}); + cx.run_until_parked(); + assert!(later.run(|_, _| {}), "queued: nothing has found the entity gone yet"); + cx.run_until_parked(); + assert_eq!(counters.later_jobs.get(), 0, "never run"); + assert!(!later.run(|_, _| {}), "the first job found the entity gone"); + } + /// What closing the window hands the runtime's shutdown: the number of /// sessions the engine was told to close, which `run` gives time to act /// on (the Slint front end does the same). The engine ignores a close for