use crate::{Error, Response, SharedScript};
use serde::Serialize;
use std::collections::BTreeMap;
use std::sync::Arc;
impl SharedScript {
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
pub async fn run_async<T: Serialize + Send + 'static>(
self: Arc<Self>,
payload: T,
) -> Result<Response, Error> {
match tokio::task::spawn_blocking(move || self.run(&payload)).await {
Ok(result) => result,
Err(join) => Err(Error::Library(format!(
"the blocking task running mnd_request did not complete: {join}"
))),
}
}
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
pub async fn run_files_async(
self: Arc<Self>,
files: Vec<(String, Vec<u8>)>,
) -> Result<BTreeMap<String, Vec<u8>>, Error> {
match tokio::task::spawn_blocking(move || self.run_files(&files)).await {
Ok(result) => result,
Err(join) => Err(Error::Library(format!(
"the blocking task running mnd_request did not complete: {join}"
))),
}
}
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
pub async fn frame_async<T: Serialize + Send + 'static>(
self: Arc<Self>,
payload: T,
) -> Result<Response, Error> {
match tokio::task::spawn_blocking(move || self.frame(&payload)).await {
Ok(result) => result,
Err(join) => Err(Error::Library(format!(
"the blocking task running mnd_request did not complete: {join}"
))),
}
}
}