aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-22 23:14:27 +0900
committernsfisis <nsfisis@gmail.com>2026-05-23 15:48:00 +0900
commit5adc4e467f01865ba2d4f519334ee1b0496b8ebf (patch)
treef6970f181793c0f8b9b67b2af54c09ae13a25c4b /crates/shirabe/src/util
parent2a1696906344cb4da768a940bf8b1f89bbc82b47 (diff)
downloadphp-shirabe-5adc4e467f01865ba2d4f519334ee1b0496b8ebf.tar.gz
php-shirabe-5adc4e467f01865ba2d4f519334ee1b0496b8ebf.tar.zst
php-shirabe-5adc4e467f01865ba2d4f519334ee1b0496b8ebf.zip
refactor(promise): change functions returning PromiseInterface to async fn
Diffstat (limited to 'crates/shirabe/src/util')
-rw-r--r--crates/shirabe/src/util/filesystem.rs6
-rw-r--r--crates/shirabe/src/util/http_downloader.rs16
-rw-r--r--crates/shirabe/src/util/loop.rs1
-rw-r--r--crates/shirabe/src/util/process_executor.rs4
-rw-r--r--crates/shirabe/src/util/sync_helper.rs22
5 files changed, 18 insertions, 31 deletions
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index 96316e9..39b5e6b 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -1,7 +1,6 @@
//! ref: composer/src/Composer/Util/Filesystem.php
use shirabe_external_packages::composer::pcre::Preg;
-use shirabe_external_packages::react::promise::PromiseInterface;
use shirabe_external_packages::symfony::component::filesystem::exception::IOException;
use shirabe_external_packages::symfony::component::finder::Finder;
use shirabe_php_shim::{
@@ -133,10 +132,7 @@ impl Filesystem {
///
/// Uses the process component if proc_open is enabled on the PHP
/// installation.
- pub fn remove_directory_async(
- &mut self,
- directory: &str,
- ) -> anyhow::Result<Box<dyn PromiseInterface>> {
+ pub async fn remove_directory_async(&mut self, directory: &str) -> anyhow::Result<bool> {
let edge_case_result = self.remove_edge_cases(directory, true)?;
if let Some(r) = edge_case_result {
return Ok(shirabe_external_packages::react::promise::resolve(Some(
diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs
index 3072df2..6f769ce 100644
--- a/crates/shirabe/src/util/http_downloader.rs
+++ b/crates/shirabe/src/util/http_downloader.rs
@@ -5,8 +5,6 @@ use indexmap::IndexMap;
use crate::util::Silencer;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
-use shirabe_external_packages::react::promise::Promise;
-use shirabe_external_packages::react::promise::PromiseInterface;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, array_replace_recursive, chr,
extension_loaded, file_get_contents, function_exists, implode, is_numeric, max, min,
@@ -203,11 +201,11 @@ impl HttpDownloader {
}
/// Create an async download operation
- pub fn add(
+ pub async fn add(
&mut self,
url: &str,
options: IndexMap<String, PhpMixed>,
- ) -> Result<Box<dyn PromiseInterface>> {
+ ) -> Result<Response> {
if "" == url {
return Err(InvalidArgumentException {
message: "$url must not be an empty string".to_string(),
@@ -255,12 +253,12 @@ impl HttpDownloader {
}
/// Create an async copy operation
- pub fn add_copy(
+ pub async fn add_copy(
&mut self,
url: &str,
to: &str,
options: IndexMap<String, PhpMixed>,
- ) -> Result<Box<dyn PromiseInterface>> {
+ ) -> Result<Response> {
if "" == url {
return Err(InvalidArgumentException {
message: "$url must not be an empty string".to_string(),
@@ -292,11 +290,7 @@ impl HttpDownloader {
/// @phpstan-param Request $request
/// @return array{Job, PromiseInterface}
- fn add_job(
- &mut self,
- mut request: Request,
- sync: bool,
- ) -> Result<(JobHandle, Box<dyn PromiseInterface>)> {
+ async fn add_job(&mut self, mut request: Request, sync: bool) -> Result<(JobHandle, Response)> {
request.options = array_replace_recursive(self.options.clone(), request.options);
let id = self.id_gen;
diff --git a/crates/shirabe/src/util/loop.rs b/crates/shirabe/src/util/loop.rs
index 1463d5e..18f2359 100644
--- a/crates/shirabe/src/util/loop.rs
+++ b/crates/shirabe/src/util/loop.rs
@@ -4,7 +4,6 @@ use crate::util::HttpDownloader;
use crate::util::ProcessExecutor;
use anyhow::Result;
use indexmap::IndexMap;
-use shirabe_external_packages::react::promise::PromiseInterface;
use shirabe_external_packages::symfony::component::console::helper::ProgressBar;
use shirabe_php_shim::microtime;
diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs
index cd25fbc..1ee821c 100644
--- a/crates/shirabe/src/util/process_executor.rs
+++ b/crates/shirabe/src/util/process_executor.rs
@@ -6,8 +6,6 @@ use indexmap::IndexMap;
use std::sync::{LazyLock, Mutex};
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
-use shirabe_external_packages::react::promise::Promise;
-use shirabe_external_packages::react::promise::PromiseInterface;
use shirabe_external_packages::seld::signal::SignalHandler;
use shirabe_external_packages::symfony::component::process::ExecutableFinder;
use shirabe_external_packages::symfony::component::process::Process;
@@ -375,7 +373,7 @@ impl ProcessExecutor {
}
/// starts a process on the commandline in async mode
- pub fn execute_async<C, W>(&mut self, command: C, cwd: W) -> Result<Box<dyn PromiseInterface>>
+ pub async fn execute_async<C, W>(&mut self, command: C, cwd: W) -> Result<Process>
where
C: IntoExecCommand,
W: IntoExecCwd,
diff --git a/crates/shirabe/src/util/sync_helper.rs b/crates/shirabe/src/util/sync_helper.rs
index f22b532..6cf2467 100644
--- a/crates/shirabe/src/util/sync_helper.rs
+++ b/crates/shirabe/src/util/sync_helper.rs
@@ -5,7 +5,7 @@ use crate::downloader::DownloaderInterface;
use crate::package::PackageInterface;
use crate::util::r#loop::Loop;
use anyhow::Result;
-use shirabe_external_packages::react::promise::PromiseInterface;
+use shirabe_php_shim::PhpMixed;
pub enum DownloaderOrManager<'a> {
Interface(&'a dyn DownloaderInterface),
@@ -13,61 +13,61 @@ pub enum DownloaderOrManager<'a> {
}
impl<'a> DownloaderOrManager<'a> {
- fn download(
+ async fn download(
&self,
package: &dyn PackageInterface,
path: &str,
prev_package: Option<&dyn PackageInterface>,
- ) -> Result<Box<dyn PromiseInterface>> {
+ ) -> Result<Option<PhpMixed>> {
match self {
Self::Interface(d) => d.download3(package, path, prev_package),
Self::Manager(d) => d.borrow().download(package, path, prev_package),
}
}
- fn prepare(
+ async fn prepare(
&self,
r#type: &str,
package: &dyn PackageInterface,
path: &str,
prev_package: Option<&dyn PackageInterface>,
- ) -> Result<Box<dyn PromiseInterface>> {
+ ) -> Result<Option<PhpMixed>> {
match self {
Self::Interface(d) => d.prepare(r#type, package, path, prev_package),
Self::Manager(d) => d.borrow().prepare(r#type, package, path, prev_package),
}
}
- fn install(
+ async fn install(
&self,
package: &dyn PackageInterface,
path: &str,
- ) -> Result<Box<dyn PromiseInterface>> {
+ ) -> Result<Option<PhpMixed>> {
match self {
Self::Interface(d) => d.install2(package, path),
Self::Manager(d) => d.borrow().install(package, path),
}
}
- fn update(
+ async fn update(
&self,
package: &dyn PackageInterface,
prev_package: &dyn PackageInterface,
path: &str,
- ) -> Result<Box<dyn PromiseInterface>> {
+ ) -> Result<Option<PhpMixed>> {
match self {
Self::Interface(d) => d.update(package, prev_package, path),
Self::Manager(d) => d.borrow().update(package, prev_package, path),
}
}
- fn cleanup(
+ async fn cleanup(
&self,
r#type: &str,
package: &dyn PackageInterface,
path: &str,
prev_package: Option<&dyn PackageInterface>,
- ) -> Result<Box<dyn PromiseInterface>> {
+ ) -> Result<Option<PhpMixed>> {
match self {
Self::Interface(d) => d.cleanup(r#type, package, path, prev_package),
Self::Manager(d) => d.borrow().cleanup(r#type, package, path, prev_package),