mirror of
https://github.com/async-rs/async-std.git
synced 2025-02-06 04:35:32 +00:00
test,docs: Add stream::pending example code
This commit is contained in:
parent
e9357c0307
commit
f53fcbb706
1 changed files with 21 additions and 0 deletions
|
@ -18,6 +18,27 @@ pub struct Pending<T> {
|
|||
/// Creates a stream that never returns any items.
|
||||
///
|
||||
/// The returned stream will always return `Pending` when polled.
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # async_std::task::block_on(async {
|
||||
/// #
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// use async_std::prelude::*;
|
||||
/// use async_std::stream;
|
||||
///
|
||||
/// let dur = Duration::from_millis(100);
|
||||
/// let mut s = stream::pending::<()>().timeout(dur);
|
||||
///
|
||||
/// let item = s.next().await;
|
||||
///
|
||||
/// assert!(item.is_some());
|
||||
/// assert!(item.unwrap().is_err());
|
||||
///
|
||||
/// #
|
||||
/// # })
|
||||
/// ```
|
||||
pub fn pending<T>() -> Pending<T> {
|
||||
Pending {
|
||||
_marker: PhantomData,
|
||||
|
|
Loading…
Reference in a new issue