From e068a9d644fde6659a88accd55b3f1d0d9d7cf46 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 23 May 2026 03:07:15 +0900 Subject: refactor(promise): rewrite promise bodies to async/await Mechanically convert promise-returning function bodies to async/await: resolve() returns the value directly, forwarding calls get .await, and simple .then chains become await sequences. Also collapse the installer double-Option (Result>> -> Result>). Hard spots that depend on the Loop::wait / job-machine boundary (accept/reject orchestration, closures capturing &mut self, batch waits) are left intact and marked with TODO(phase-c-promise) for manual porting. The crate does not compile yet; traits still need #[async_trait]. Co-Authored-By: Claude Opus 4.7 --- .../shirabe/src/installer/installation_manager.rs | 32 ++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'crates/shirabe/src/installer/installation_manager.rs') diff --git a/crates/shirabe/src/installer/installation_manager.rs b/crates/shirabe/src/installer/installation_manager.rs index 114f1fc..ae0470a 100644 --- a/crates/shirabe/src/installer/installation_manager.rs +++ b/crates/shirabe/src/installer/installation_manager.rs @@ -285,6 +285,8 @@ impl InstallationManager { download_only: bool, all_operations: Vec>, ) -> Result<()> { + // TODO(phase-c-promise): Loop::wait-driven batch orchestration (download/cleanup promises); + // rewrite to await collected futures once the async Loop boundary lands. let mut promises: Vec> = vec![]; for (index, operation) in &operations { @@ -401,6 +403,8 @@ impl InstallationManager { run_scripts: bool, all_operations: &[Box], ) -> Result<()> { + // TODO(phase-c-promise): Loop::wait-driven batch orchestration (prepare/install promises); + // rewrite to await collected futures once the async Loop boundary lands. let mut promises: Vec> = vec![]; let mut post_exec_callbacks: Vec> = vec![]; @@ -513,6 +517,7 @@ impl InstallationManager { /// @param array> $promises fn wait_on_promises(&mut self, promises: Vec>) { + // TODO(phase-c-promise): thin wrapper over Loop::wait (the async boundary owned separately). let mut progress: Option<()> = None; // TODO(phase-b): self.io instanceof ConsoleIO downcast let io_is_console = false; @@ -541,7 +546,7 @@ impl InstallationManager { /// @phpstan-return PromiseInterface|null pub async fn download(&mut self, package: &dyn PackageInterface) -> Option { let installer = self.get_installer(package.get_type()).ok()?; - let promise = installer.cleanup("install", package, None).ok()?; + let promise = installer.cleanup("install", package, None).await.ok()?; promise } @@ -556,7 +561,7 @@ impl InstallationManager { ) -> Option { let package = operation.get_package(); let installer = self.get_installer(package.get_type()).ok()?; - let promise = installer.install(repo, package).ok()?; + let promise = installer.install(repo, package).await.ok()?; self.mark_for_notification(package); promise @@ -578,24 +583,19 @@ impl InstallationManager { let promise = if initial_type == target_type { let installer = self.get_installer(initial_type).ok()?; - let promise = installer.update(repo, initial, target).ok()?; + let promise = installer.update(repo, initial, target).await.ok()?; self.mark_for_notification(target); promise } else { - let promise = self + // PHP: uninstall initial, then install target via the target-type installer. + let _ = self .get_installer(initial_type) .ok()? .uninstall(repo, initial) + .await .ok()?; - let promise = match promise { - Some(p) => p, - None => promise::resolve(None), - }; - - let target_type = target_type.to_string(); - // TODO(phase-b): promise.then(closure capturing self/installer) - let _ = target_type; - Some(promise) + let installer = self.get_installer(target_type).ok()?; + installer.install(repo, target).await.ok()? }; promise @@ -612,7 +612,7 @@ impl InstallationManager { let package = operation.get_package(); let installer = self.get_installer(package.get_type()).ok()?; - installer.uninstall(repo, package).ok()? + installer.uninstall(repo, package).await.ok()? } /// Executes markAliasInstalled operation. @@ -653,6 +653,8 @@ impl InstallationManager { } pub fn notify_installs(&mut self, _io: &dyn IOInterface) { + // TODO(phase-c-promise): collects http_downloader.add() promises and drives them via Loop::wait; + // rewrite to await the collected futures once the async Loop boundary lands. let mut promises: Vec> = vec![]; let result: Result<()> = (|| -> Result<()> { @@ -802,6 +804,8 @@ impl InstallationManager { &mut self, cleanup_promises: &IndexMap Option>>>, ) { + // TODO(phase-c-promise): runs cleanup closures and drives them via Loop::wait; + // rewrite once the async Loop boundary and async cleanup closures land. let mut promises: Vec> = vec![]; self.loop_.borrow().abort_jobs(); -- cgit v1.3.1