mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00

Migrate to std::futures and the futures 0.3 preview and use async/await where possible **Breaking change:** the IoFuture and IoStream definitions used to refer to Box<dyn Future> and Box<dyn Stream>, but now they are defined as Pin<...> versions which are technically breaking. No other breaking or functional changes have been made
32 lines
802 B
Rust
32 lines
802 B
Rust
#![cfg(unix)]
|
|
#![deny(warnings, rust_2018_idioms)]
|
|
|
|
use futures_util::future::FutureExt;
|
|
use libc::{c_int, getpid, kill};
|
|
use std::future::Future;
|
|
use std::time::Duration;
|
|
use tokio_timer::Timeout;
|
|
|
|
pub use futures_util::future;
|
|
pub use futures_util::stream::StreamExt;
|
|
pub use tokio::runtime::current_thread::{self, Runtime as CurrentThreadRuntime};
|
|
pub use tokio_signal::unix::Signal;
|
|
|
|
pub fn with_timeout<F: Future>(future: F) -> impl Future<Output = F::Output> {
|
|
Timeout::new(future, Duration::from_secs(1)).map(Result::unwrap)
|
|
}
|
|
|
|
pub fn run_with_timeout<F>(rt: &mut CurrentThreadRuntime, future: F) -> F::Output
|
|
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);
|
|
}
|
|
}
|