diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-23 03:07:15 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-23 15:48:00 +0900 |
| commit | e068a9d644fde6659a88accd55b3f1d0d9d7cf46 (patch) | |
| tree | bb719a70eb8c840957a94a5601df8961055ceb0f /crates/shirabe/src/downloader/zip_downloader.rs | |
| parent | 60eb89529c8af2e4477e0bb65ed9e0f2dc7d3dd7 (diff) | |
| download | php-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/downloader/zip_downloader.rs')
| -rw-r--r-- | crates/shirabe/src/downloader/zip_downloader.rs | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs index ef18f95..88b3d3a 100644 --- a/crates/shirabe/src/downloader/zip_downloader.rs +++ b/crates/shirabe/src/downloader/zip_downloader.rs @@ -192,7 +192,9 @@ impl ZipDownloader { } } - self.inner.download(package, path, prev_package, output) + self.inner + .download(package, path, prev_package, output) + .await } async fn extract_with_system_unzip( @@ -211,7 +213,7 @@ impl ZipDownloader { .as_ref() .map_or(true, |v| v.is_empty()); if unzip_commands_empty { - return self.extract_with_zip_archive(package, file, path); + return self.extract_with_zip_archive(package, file, path).await; } let command_spec = UNZIP_COMMANDS.lock().unwrap().as_ref().unwrap()[0].clone(); @@ -268,6 +270,8 @@ impl ZipDownloader { } } + // TODO(phase-c-promise): execute_async + .then fallback closure captures &mut self/io; + // recursive promise flattening, not a mechanical await chain. // TODO(phase-b): full try_fallback closure deferred — PHP captures `$io`, `$self` // and several locals by reference, conflicting with Rust's borrow checker because // `extract_with_zip_archive` later needs `&mut self`. Restructure once the @@ -350,7 +354,7 @@ impl ZipDownloader { if extract_result { zip_archive.close(); - return Ok(shirabe_external_packages::react::promise::resolve(None)); + return Ok(None); } return Err(RuntimeException { @@ -392,7 +396,7 @@ impl ZipDownloader { file: &str, path: &str, ) -> Result<Option<PhpMixed>> { - self.extract_with_system_unzip(package, file, path) + self.extract_with_system_unzip(package, file, path).await } pub fn get_error_message(&self, retval: i64, file: &str) -> String { @@ -433,7 +437,9 @@ impl crate::downloader::DownloaderInterface for ZipDownloader { prev_package: Option<&dyn PackageInterface>, output: bool, ) -> Result<Option<PhpMixed>> { - self.inner.download(package, path, prev_package, output) + self.inner + .download(package, path, prev_package, output) + .await } async fn prepare( @@ -443,7 +449,9 @@ impl crate::downloader::DownloaderInterface for ZipDownloader { path: &str, prev_package: Option<&dyn PackageInterface>, ) -> Result<Option<PhpMixed>> { - self.inner.prepare(r#type, package, path, prev_package) + self.inner + .prepare(r#type, package, path, prev_package) + .await } async fn install( @@ -452,7 +460,7 @@ impl crate::downloader::DownloaderInterface for ZipDownloader { path: &str, output: bool, ) -> Result<Option<PhpMixed>> { - self.inner.install(package, path, output) + self.inner.install(package, path, output).await } async fn update( @@ -461,7 +469,7 @@ impl crate::downloader::DownloaderInterface for ZipDownloader { target: &dyn PackageInterface, path: &str, ) -> Result<Option<PhpMixed>> { - self.inner.update(initial, target, path) + self.inner.update(initial, target, path).await } async fn remove( @@ -470,7 +478,7 @@ impl crate::downloader::DownloaderInterface for ZipDownloader { path: &str, output: bool, ) -> Result<Option<PhpMixed>> { - self.inner.remove(package, path, output) + self.inner.remove(package, path, output).await } async fn cleanup( @@ -480,6 +488,8 @@ impl crate::downloader::DownloaderInterface for ZipDownloader { path: &str, prev_package: Option<&dyn PackageInterface>, ) -> Result<Option<PhpMixed>> { - self.inner.cleanup(r#type, package, path, prev_package) + self.inner + .cleanup(r#type, package, path, prev_package) + .await } } |
