DEBT #91 — click-to-stop during Asked wakes the header read
Browse files at this commit4de1efe581a0d15a5a8a5a594dac2d071e5515e5Parent: ba29145- fix
- DEBT #91 — click-to-stop during Asked wakes the header read
4 changed files +47 -15
- crates/app/src/importing.rs +7 -1
- crates/app/src/player/library.rs +14 -13
- crates/app/src/tests/cards.rs +25 -0
- crates/app/src/ui/dock_stance.rs +1 -1
crates/app/src/importing.rsmodified+7 -1
| @@ -86,7 +86,13 @@ pub(crate) enum Proxy { | |||
| 86 | /// own state because it is what makes "how many are in flight" a number: | 86 | /// own state because it is what makes "how many are in flight" a number: |
| 87 | /// the answer comes back on a worker, and until it does this file may still | 87 | /// the answer comes back on a worker, and until it does this file may still |
| 88 | /// turn into an encode. | 88 | /// turn into an encode. |
| 89 | - Asked, | 89 | + /// |
| 90 | + /// Carries the flag [`engine::proxy::generate_if_wanted`] polls at the door | ||
| 91 | + /// and around the header read: the same shape [`Self::Making`] carries a | ||
| 92 | + /// cancellable [`engine::proxy::Job`] with, one step earlier -- there is no | ||
| 93 | + /// `Job` yet to hold, so the raw flag is what a stop asked during this | ||
| 94 | + /// state has to set. | ||
| 95 | + Asked(std::sync::Arc<std::sync::atomic::AtomicBool>), | ||
| 90 | /// A file this machine cuts at speed as it is: no stand-in, and none | 96 | /// A file this machine cuts at speed as it is: no stand-in, and none |
| 91 | /// wanted ([`engine::proxy::wanted`]). | 97 | /// wanted ([`engine::proxy::wanted`]). |
| 92 | Native, | 98 | Native, |
crates/app/src/player/library.rsmodified+14 -13
| @@ -621,18 +621,15 @@ impl Player { | |||
| 621 | /// film's stand-in has asked, and is told by the row how far it has got. | 621 | /// film's stand-in has asked, and is told by the row how far it has got. |
| 622 | pub(crate) fn start_proxy_for(&mut self, path: &std::path::Path, cx: &mut Context<Self>) { | 622 | pub(crate) fn start_proxy_for(&mut self, path: &std::path::Path, cx: &mut Context<Self>) { |
| 623 | let path = path.to_path_buf(); | 623 | let path = path.to_path_buf(); |
| 624 | - self.proxies.insert(path.clone(), Proxy::Asked); | 624 | + // The same flag [`engine::proxy::generate_if_wanted`] polls at the door |
| 625 | + // and around the header read: a click on the row while the header is | ||
| 626 | + // still being walked ([`Player::toggle_proxy`]'s `Asked` arm) sets it, | ||
| 627 | + // so the walk unwinds mid-read instead of running to completion. | ||
| 628 | + let cancel = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)); | ||
| 629 | + self.proxies.insert(path.clone(), Proxy::Asked(cancel.clone())); | ||
| 625 | let started = cx.background_executor().spawn({ | 630 | let started = cx.background_executor().spawn({ |
| 626 | let path = path.clone(); | 631 | let path = path.clone(); |
| 627 | - // deferred: DEBT #91 wires only the engine's header-read cancel | 632 | + async move { engine::proxy::generate_if_wanted(&path, &cancel) } |
| 628 | - // (crates/engine/src/proxy.rs); the app has no cancel to hand it | ||
| 629 | - // yet -- a stop asked during Asked still lands the way it always | ||
| 630 | - // has, by the `stopped` check below once the ask returns. Wiring | ||
| 631 | - // this flag to `toggle_proxy` is the next slice. | ||
| 632 | - async move { | ||
| 633 | - let uncancelled = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)); | ||
| 634 | - engine::proxy::generate_if_wanted(&path, &uncancelled) | ||
| 635 | - } | ||
| 636 | }); | 633 | }); |
| 637 | cx.spawn(async move |this, cx| { | 634 | cx.spawn(async move |this, cx| { |
| 638 | let started = started.await; | 635 | let started = started.await; |
| @@ -644,7 +641,7 @@ impl Player { | |||
| 644 | // half of a click made during the ask is an encoder nothing in | 641 | // half of a click made during the ask is an encoder nothing in |
| 645 | // the map can reach -- and it finishes minutes later and puts | 642 | // the map can reach -- and it finishes minutes later and puts |
| 646 | // back the stand-in somebody switched off. | 643 | // back the stand-in somebody switched off. |
| 647 | - let stopped = !matches!(this.proxies.get(&path), Some(Proxy::Asked)); | 644 | + let stopped = !matches!(this.proxies.get(&path), Some(Proxy::Asked(_))); |
| 648 | let state = match started { | 645 | let state = match started { |
| 649 | // Cancelled and *held*, exactly as a stop of a running one | 646 | // Cancelled and *held*, exactly as a stop of a running one |
| 650 | // is: the worker's own answer is what settles it, so an | 647 | // is: the worker's own answer is what settles it, so an |
| @@ -718,7 +715,11 @@ impl Player { | |||
| 718 | Some(Proxy::Making(_)) => self.cancel_proxy(path, cx), | 715 | Some(Proxy::Making(_)) => self.cancel_proxy(path, cx), |
| 719 | // Already winding down: the second click on a stop is nothing. | 716 | // Already winding down: the second click on a stop is nothing. |
| 720 | Some(Proxy::Cancelling(_)) => {} | 717 | Some(Proxy::Cancelling(_)) => {} |
| 721 | - Some(Proxy::Asked) => { | 718 | + Some(Proxy::Asked(cancel)) => { |
| 719 | + // Wakes the header read mid-walk ([`engine::proxy::started`]): | ||
| 720 | + // without this the stop only ever landed once the read had | ||
| 721 | + // already run to completion on its own (DEBT #91). | ||
| 722 | + cancel.store(true, std::sync::atomic::Ordering::Release); | ||
| 722 | engine::proxy::set_off(path, true); | 723 | engine::proxy::set_off(path, true); |
| 723 | self.proxies.insert(path.to_path_buf(), Proxy::Cancelled); | 724 | self.proxies.insert(path.to_path_buf(), Proxy::Cancelled); |
| 724 | let text = format!("STOPPING the stand-in for {}…", file_name(path)); | 725 | let text = format!("STOPPING the stand-in for {}…", file_name(path)); |
| @@ -868,7 +869,7 @@ impl Player { | |||
| 868 | pub(crate) fn in_flight_proxies(&self) -> usize { | 869 | pub(crate) fn in_flight_proxies(&self) -> usize { |
| 869 | self.proxies | 870 | self.proxies |
| 870 | .values() | 871 | .values() |
| 871 | - .filter(|p| matches!(p, Proxy::Asked | Proxy::Making(_) | Proxy::Cancelling(_))) | 872 | + .filter(|p| matches!(p, Proxy::Asked(_) | Proxy::Making(_) | Proxy::Cancelling(_))) |
| 872 | .count() | 873 | .count() |
| 873 | } | 874 | } |
| 874 | 875 | ||
crates/app/src/tests/cards.rsmodified+25 -0
| @@ -2084,3 +2084,28 @@ fn darkroom_source_rows_keep_proxy_add_and_media_audio_text_paths() { | |||
| 2084 | ); | 2084 | ); |
| 2085 | } | 2085 | } |
| 2086 | } | 2086 | } |
| 2087 | + | ||
| 2088 | +/// DEBT #91: a click-to-stop while a stand-in's header is still being read | ||
| 2089 | +/// must reach the flag the read itself polls (`engine::proxy::started`), not | ||
| 2090 | +/// only relabel the row. Read off the source and not run, the way the row | ||
| 2091 | +/// above it is -- there is no `TestAppContext` in this binary to construct a | ||
| 2092 | +/// `Context<Player>` and call `toggle_proxy` on. On the state this fix | ||
| 2093 | +/// replaced, `start_proxy_for` handed the header read a flag nothing outside | ||
| 2094 | +/// it could reach and `Proxy::Asked` carried no field to store a stop into, | ||
| 2095 | +/// so `library.find("Proxy::Asked(cancel)")` below has nothing to find. | ||
| 2096 | +#[test] | ||
| 2097 | +fn toggle_proxy_wakes_the_asked_phase_it_stops() { | ||
| 2098 | + let library = src_text("player/library.rs"); | ||
| 2099 | + let start = &library[library.find("fn start_proxy_for(").expect("start_proxy_for")..]; | ||
| 2100 | + assert!( | ||
| 2101 | + start.contains("generate_if_wanted(&path, &cancel)"), | ||
| 2102 | + "start_proxy_for no longer hands the header read a cancel flag anyone can reach" | ||
| 2103 | + ); | ||
| 2104 | + let toggle = &library[library.find("fn toggle_proxy(").expect("toggle_proxy")..]; | ||
| 2105 | + let asked_arm = | ||
| 2106 | + &toggle[toggle.find("Proxy::Asked(cancel)").expect("the Asked arm's own flag")..]; | ||
| 2107 | + assert!( | ||
| 2108 | + asked_arm.contains("cancel.store(true"), | ||
| 2109 | + "a stop asked during Asked no longer sets the flag the header read polls" | ||
| 2110 | + ); | ||
| 2111 | +} | ||
crates/app/src/ui/dock_stance.rsmodified+1 -1
| @@ -293,7 +293,7 @@ fn source_row( | |||
| 293 | true, | 293 | true, |
| 294 | format!("Stopping the stand-in for {}…", row.name), | 294 | format!("Stopping the stand-in for {}…", row.name), |
| 295 | ), | 295 | ), |
| 296 | - Some(Proxy::Asked) => ( | 296 | + Some(Proxy::Asked(_)) => ( |
| 297 | "○", | 297 | "○", |
| 298 | false, | 298 | false, |
| 299 | None, | 299 | None, |