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 <noreply@anthropic.com>
This commit is contained in:
1 parent
efc7db57a3
commit
6852204277
1 file changed
+20
-1
@@ -47,7 +47,11 @@ type Job = Box<dyn FnOnce(&mut AppState, &mut Context<AppState>) + Send>;
|
|||||||
pub struct Later(UnboundedSender<Job>);
|
pub struct Later(UnboundedSender<Job>);
|
||||||
|
|
||||||
impl Later {
|
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(
|
pub fn run(
|
||||||
&self,
|
&self,
|
||||||
job: impl FnOnce(&mut AppState, &mut Context<AppState>) + Send + 'static,
|
job: impl FnOnce(&mut AppState, &mut Context<AppState>) + Send + 'static,
|
||||||
@@ -371,6 +375,21 @@ mod tests {
|
|||||||
assert_eq!(counters.later_jobs.get(), 1);
|
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
|
/// 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
|
/// 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
|
/// on (the Slint front end does the same). The engine ignores a close for
|
||||||
|
|||||||
Reference in new issue
Block a user