#[allow(warnings)]
#[cfg(feature = "asyncrs")]
pub mod asyncrs {
pub use tokio;
pub use tokio::runtime::Runtime;
pub use tokio::*;
use crate::Vector;
use std::future::Future;
pub trait BlockOn: Future + Send + 'static {
fn block_on(self) -> Self::Output
where
Self: Sized,
{
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
rt.block_on(self)
}
}
impl<F, T> BlockOn for F where F: Future<Output = T> + Send + 'static {}
pub fn block_on<F, T>(future: F) -> T
where
F: std::future::Future<Output = T> + Send + 'static,
{
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
rt.block_on(future)
}
pub async fn command(command: impl AsRef<[u8]>) -> std::process::Output {
use std::process::Stdio;
use tokio::process::Command;
let command = command.as_ref().to_string_lossy().to_string();
let exe = command.split(" ").into_iter().nth(0).unwrap();
let other = command.split(" ").into_iter().skip(1).collect::<Vec<_>>();
let child = Command::new(exe)
.args(other)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.expect("Failed to spawn child process");
let output = child
.wait_with_output()
.await
.expect("Failed to wait on child");
output
}
}
#[cfg(feature = "asyncrs")]
pub use asyncrs::*;