async_compatibility_layer/art/
async-std.rs

1use async_std::prelude::FutureExt;
2pub use async_std::{
3    io::{ReadExt as AsyncReadExt, WriteExt as AsyncWriteExt},
4    main as async_main,
5    net::TcpStream,
6    task::{
7        block_on as async_block_on, block_on as async_block_on_with_runtime, sleep as async_sleep,
8        spawn as async_spawn, spawn_local as async_spawn_local, yield_now as async_yield_now,
9    },
10    test as async_test,
11};
12use std::future::Future;
13use std::time::Duration;
14/// executor stream abstractions
15pub mod stream {
16    /// executor strean timeout abstractions
17    pub mod to {
18        pub use async_std::stream::Timeout;
19    }
20}
21/// executor future abstractions
22pub mod future {
23    /// executor future timeout abstractions
24    pub mod to {
25        pub use async_std::future::TimeoutError;
26        /// Result from await of timeout on future
27        pub type Result<T> = std::result::Result<T, async_std::future::TimeoutError>;
28    }
29}
30
31/// Provides timeout with `async_std` that matches `tokio::time::timeout`
32pub fn async_timeout<T>(
33    duration: Duration,
34    future: T,
35) -> impl Future<Output = Result<T::Output, async_std::future::TimeoutError>>
36where
37    T: Future,
38{
39    future.timeout(duration)
40}
41
42/// Splits a `TcpStream` into reader and writer
43#[must_use]
44pub fn split_stream(stream: TcpStream) -> (TcpStream, TcpStream) {
45    (stream.clone(), stream)
46}