#[cfg(feature = "async_tokio")]
use tokio::task;
use crate::{process::ProcRuntime, PhpCallResult, PhpError, PhpValue, RuntimeConfig, PhpRuntime};
#[cfg(feature = "async_tokio")]
pub async fn call_async(cfg: RuntimeConfig, function: String, args: Vec<PhpValue>) -> Result<PhpCallResult, PhpError> {
let handle = task::spawn_blocking(move || -> Result<PhpCallResult, PhpError> {
let mut rt = ProcRuntime::spawn(cfg)?;
rt.call(&function, &args)
});
match handle.await {
Ok(res) => res,
Err(e) => Err(PhpError { message: format!("join error: {e}") }),
}
}
#[cfg(feature = "async_tokio")]
pub async fn eval_async(cfg: RuntimeConfig, code: String) -> Result<PhpCallResult, PhpError> {
let handle = task::spawn_blocking(move || -> Result<PhpCallResult, PhpError> {
let mut rt = ProcRuntime::spawn(cfg)?;
rt.eval(&code)
});
match handle.await {
Ok(res) => res,
Err(e) => Err(PhpError { message: format!("join error: {e}") }),
}
}
#[cfg(feature = "async_tokio")]
pub async fn include_async(cfg: RuntimeConfig, path: String) -> Result<PhpCallResult, PhpError> {
let handle = task::spawn_blocking(move || -> Result<PhpCallResult, PhpError> {
let mut rt = ProcRuntime::spawn(cfg)?;
rt.include(&path)
});
match handle.await {
Ok(res) => res,
Err(e) => Err(PhpError { message: format!("join error: {e}") }),
}
}