Files
tokio/tokio-net/tests/support.rs
T

35 lines
871 B
Rust
Raw Normal View History

#![warn(rust_2018_idioms)]
#![allow(dead_code)]
2018-09-02 11:32:50 +02:00
2019-08-17 13:43:55 -07:00
pub use tokio::runtime::current_thread::{self, Runtime as CurrentThreadRuntime};
use tokio::timer::Timeout;
#[cfg(all(unix, feature = "signal"))]
pub use tokio_net::signal::unix::{signal, SignalKind};
2019-08-17 13:43:55 -07:00
pub use futures_util::future;
2019-07-03 10:40:59 -07:00
use futures_util::future::FutureExt;
2019-08-17 13:43:55 -07:00
pub use futures_util::stream::StreamExt;
#[cfg(unix)]
2019-05-14 10:27:36 -07:00
use libc::{c_int, getpid, kill};
2019-07-03 10:40:59 -07:00
use std::future::Future;
2019-02-21 11:56:15 -08:00
use std::time::Duration;
2018-07-28 12:30:46 -07:00
2019-07-03 10:40:59 -07:00
pub fn with_timeout<F: Future>(future: F) -> impl Future<Output = F::Output> {
Timeout::new(future, Duration::from_secs(3)).map(Result::unwrap)
2018-09-02 11:32:50 +02:00
}
2018-07-28 12:30:46 -07:00
2019-07-03 10:40:59 -07:00
pub fn run_with_timeout<F>(rt: &mut CurrentThreadRuntime, future: F) -> F::Output
2019-02-21 11:56:15 -08:00
where
F: Future,
2018-09-02 11:32:50 +02:00
{
rt.block_on(with_timeout(future))
2018-07-28 12:30:46 -07:00
}
#[cfg(unix)]
pub fn send_signal(signal: c_int) {
unsafe {
assert_eq!(kill(getpid(), signal), 0);
}
}