1use std::future::Future;
2use std::pin::Pin;
3
4pub use tokio::net::TcpStream;
5pub use tokio::time::interval;
6pub use tokio::time::sleep;
7pub use tokio::time::timeout;
8pub use tokio::time::Instant;
9pub use tokio::time::MissedTickBehavior;
10pub use tokio_stream::Stream;
11
12pub type JoinHandle<T> = TokioJoinHandle<T>;
13pub type Interval = tokio::time::Interval;
14
15#[derive(Debug)]
16pub struct TokioJoinHandle<T> {
17 handle: tokio::task::JoinHandle<T>,
18}
19
20pub fn spawn<F>(future: F) -> JoinHandle<F::Output>
21where
22 F: Future + Send + 'static,
23 F::Output: Send + 'static,
24{
25 TokioJoinHandle { handle: tokio::task::spawn(future) }
26}
27
28impl<T> Future for TokioJoinHandle<T> {
29 type Output = T;
30
31 fn poll(
32 mut self: std::pin::Pin<&mut Self>,
33 cx: &mut std::task::Context<'_>,
34 ) -> std::task::Poll<Self::Output> {
35 let this = &mut *self;
36 let mut handle = &mut this.handle;
37 match Pin::new(&mut handle).poll(cx) {
38 std::task::Poll::Ready(value) => {
39 std::task::Poll::Ready(value.expect("Tasks should not panic"))
40 }
41 std::task::Poll::Pending => std::task::Poll::Pending,
42 }
43 }
44}