aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/installer/installation_manager.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-23 03:07:15 +0900
committernsfisis <nsfisis@gmail.com>2026-05-23 15:48:00 +0900
commite068a9d644fde6659a88accd55b3f1d0d9d7cf46 (patch)
treebb719a70eb8c840957a94a5601df8961055ceb0f /crates/shirabe/src/installer/installation_manager.rs
parent60eb89529c8af2e4477e0bb65ed9e0f2dc7d3dd7 (diff)
downloadphp-shirabe-e068a9d644fde6659a88accd55b3f1d0d9d7cf46.tar.gz
php-shirabe-e068a9d644fde6659a88accd55b3f1d0d9d7cf46.tar.zst
php-shirabe-e068a9d644fde6659a88accd55b3f1d0d9d7cf46.zip
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<Option<Option<PhpMixed>>> -> Result<Option<PhpMixed>>). 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 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/installer/installation_manager.rs')
-rw-r--r--crates/shirabe/src/installer/installation_manager.rs32
1 files changed, 18 insertions, 14 deletions
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<Box<dyn OperationInterface>>,
) -> 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<Box<dyn PromiseInterface>> = vec![];
for (index, operation) in &operations {
@@ -401,6 +403,8 @@ impl InstallationManager {
run_scripts: bool,
all_operations: &[Box<dyn OperationInterface>],
) -> 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<Box<dyn PromiseInterface>> = vec![];
let mut post_exec_callbacks: Vec<Box<dyn Fn()>> = vec![];
@@ -513,6 +517,7 @@ impl InstallationManager {
/// @param array<PromiseInterface<void|null>> $promises
fn wait_on_promises(&mut self, promises: Vec<Box<dyn PromiseInterface>>) {
+ // 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<void|null>|null
pub async fn download(&mut self, package: &dyn PackageInterface) -> Option<PhpMixed> {
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<PhpMixed> {
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<Box<dyn PromiseInterface>> = vec![];
let result: Result<()> = (|| -> Result<()> {
@@ -802,6 +804,8 @@ impl InstallationManager {
&mut self,
cleanup_promises: &IndexMap<i64, Box<dyn Fn() -> Option<Box<dyn PromiseInterface>>>>,
) {
+ // 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<Box<dyn PromiseInterface>> = vec![];
self.loop_.borrow().abort_jobs();