#[allow(warnings)]
#[cfg(feature = "asyncrs")]
pub mod asyncrs {
pub use tokio::runtime::Runtime;
pub use tokio::*;
use crate::Vector;
pub trait BlockOn {
fn block_on<F>(&self, future: F)
where
F: std::future::Future<Output = ()> + Send + 'static;
}
impl BlockOn for () {
fn block_on<F>(&self, future: F)
where
F: std::future::Future<Output = ()> + Send + 'static,
{
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(future);
}
}
pub fn block_on<F>(future: F)
where
F: std::future::Future<Output = ()> + Send + 'static,
{
let rt = tokio::runtime::Runtime::new().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::*;