mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-16 00:00:12 +02:00
30 lines
681 B
Rust
30 lines
681 B
Rust
#![warn(rust_2018_idioms)]
|
|
|
|
use futures_util::future;
|
|
use futures_util::future::FutureExt;
|
|
use std::env;
|
|
use std::future::Future;
|
|
use std::time::Duration;
|
|
use tokio::timer::Timeout;
|
|
use tokio_process::Command;
|
|
|
|
#[allow(dead_code)]
|
|
pub fn cmd(s: &str) -> Command {
|
|
let mut me = env::current_exe().unwrap();
|
|
me.pop();
|
|
if me.ends_with("deps") {
|
|
me.pop();
|
|
}
|
|
me.push(s);
|
|
Command::new(me)
|
|
}
|
|
|
|
pub fn with_timeout<F: Future>(future: F) -> impl Future<Output = F::Output> {
|
|
Timeout::new(future, Duration::from_secs(3)).then(|r| {
|
|
if r.is_err() {
|
|
panic!("timed out {:?}", r.err());
|
|
}
|
|
future::ready(r.unwrap())
|
|
})
|
|
}
|