mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00

* Don't use tokio-core any more for tests. That one brings tokio from crates.io instead of the current workspace and two versions of that don't want to cooperate. * Guard unix-specific examples on windows. * Leave CI setup to top-level directory.
39 lines
1.0 KiB
Rust
39 lines
1.0 KiB
Rust
#![cfg(unix)]
|
|
|
|
extern crate libc;
|
|
extern crate futures;
|
|
extern crate tokio;
|
|
extern crate tokio_signal;
|
|
|
|
use self::libc::{c_int, getpid, kill};
|
|
use std::time::Duration;
|
|
use self::tokio::timer::Timeout;
|
|
|
|
pub use self::futures::{Future, Stream};
|
|
pub use self::tokio::runtime::current_thread::{self, Runtime as CurrentThreadRuntime};
|
|
pub use self::tokio_signal::unix::Signal;
|
|
|
|
pub fn with_timeout<F: Future>(future: F) -> impl Future<Item = F::Item, Error = F::Error> {
|
|
Timeout::new(future, Duration::from_secs(1))
|
|
.map_err(|e| if e.is_timer() {
|
|
panic!("failed to register timer");
|
|
} else if e.is_elapsed() {
|
|
panic!("timed out")
|
|
} else {
|
|
e.into_inner().expect("missing inner error")
|
|
})
|
|
}
|
|
|
|
pub fn run_with_timeout<F>(rt: &mut CurrentThreadRuntime, future: F) -> Result<F::Item, F::Error>
|
|
where F: Future
|
|
{
|
|
rt.block_on(with_timeout(future))
|
|
}
|
|
|
|
#[cfg(unix)]
|
|
pub fn send_signal(signal: c_int) {
|
|
unsafe {
|
|
assert_eq!(kill(getpid(), signal), 0);
|
|
}
|
|
}
|