Skip to content

Commit 99e25aa

Browse files
taiki-ecramertj
authored andcommitted
Use await syntax for most examples
1 parent 0fbab45 commit 99e25aa

File tree

11 files changed

+130
-71
lines changed

11 files changed

+130
-71
lines changed

futures-test/src/future/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,16 @@ pub trait FutureTestExt: Future {
6161
///
6262
/// ```
6363
/// #![feature(async_await)]
64+
/// # futures::executor::block_on(async {
6465
/// use futures::channel::oneshot;
65-
/// use futures::executor::block_on;
6666
/// use futures_test::future::FutureTestExt;
6767
///
6868
/// let (tx, rx) = oneshot::channel::<i32>();
6969
///
7070
/// (async { tx.send(5).unwrap() }).run_in_background();
7171
///
72-
/// assert_eq!(block_on(rx), Ok(5));
72+
/// assert_eq!(rx.await, Ok(5));
73+
/// # });
7374
/// ```
7475
fn run_in_background(self)
7576
where

futures-util/src/future/abortable.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ impl<Fut> Abortable<Fut> where Fut: Future {
2929
/// Example:
3030
///
3131
/// ```
32+
/// #![feature(async_await)]
33+
/// # futures::executor::block_on(async {
3234
/// use futures::future::{ready, Abortable, AbortHandle, Aborted};
33-
/// use futures::executor::block_on;
3435
///
3536
/// let (abort_handle, abort_registration) = AbortHandle::new_pair();
3637
/// let future = Abortable::new(ready(2), abort_registration);
3738
/// abort_handle.abort();
38-
/// assert_eq!(block_on(future), Err(Aborted));
39+
/// assert_eq!(future.await, Err(Aborted));
40+
/// # });
3941
/// ```
4042
pub fn new(future: Fut, reg: AbortRegistration) -> Self {
4143
Abortable {
@@ -68,13 +70,16 @@ impl AbortHandle {
6870
/// Example:
6971
///
7072
/// ```
73+
/// #![feature(async_await)]
74+
/// # futures::executor::block_on(async {
7175
/// use futures::future::{ready, Abortable, AbortHandle, Aborted};
72-
/// use futures::executor::block_on;
7376
///
7477
/// let (abort_handle, abort_registration) = AbortHandle::new_pair();
7578
/// let future = Abortable::new(ready(2), abort_registration);
7679
/// abort_handle.abort();
77-
/// assert_eq!(block_on(future), Err(Aborted));
80+
/// assert_eq!(future.await, Err(Aborted));
81+
/// # });
82+
/// ```
7883
pub fn new_pair() -> (Self, AbortRegistration) {
7984
let inner = Arc::new(AbortInner {
8085
waker: AtomicWaker::new(),

futures-util/src/future/fuse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<Fut: Future> Fuse<Fut> {
2727
/// # Examples
2828
///
2929
/// ```
30-
/// #![feature(async_await, futures_api)]
30+
/// #![feature(async_await)]
3131
/// # futures::executor::block_on(async {
3232
/// use futures::channel::mpsc;
3333
/// use futures::future::{Fuse, FusedFuture, FutureExt};

futures-util/src/future/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ pub trait FutureExt: Future {
451451
/// // synchronous function to better illustrate the cross-thread aspect of
452452
/// // the `shared` combinator.
453453
///
454+
/// #![feature(async_await)]
455+
/// # futures::executor::block_on(async {
454456
/// use futures::future::{self, FutureExt};
455457
/// use futures::executor::block_on;
456458
/// use std::thread;
@@ -461,8 +463,9 @@ pub trait FutureExt: Future {
461463
/// let join_handle = thread::spawn(move || {
462464
/// assert_eq!(6, block_on(shared2));
463465
/// });
464-
/// assert_eq!(6, block_on(shared1));
466+
/// assert_eq!(6, shared1.await);
465467
/// join_handle.join().unwrap();
468+
/// # });
466469
/// ```
467470
#[cfg(feature = "std")]
468471
fn shared(self) -> Shared<Self>

futures-util/src/sink/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ pub trait SinkExt<Item>: Sink<Item> {
8686
/// # Examples
8787
///
8888
/// ```
89+
/// #![feature(async_await)]
90+
/// # futures::executor::block_on(async {
8991
/// use futures::channel::mpsc;
90-
/// use futures::executor::block_on;
9192
/// use futures::sink::SinkExt;
9293
/// use futures::stream::StreamExt;
9394
/// use std::collections::VecDeque;
@@ -98,10 +99,11 @@ pub trait SinkExt<Item>: Sink<Item> {
9899
/// VecDeque::from(vec![Ok(42); x])
99100
/// });
100101
///
101-
/// block_on(tx.send(5)).unwrap();
102+
/// tx.send(5).await.unwrap();
102103
/// drop(tx);
103-
/// let received: Vec<i32> = block_on(rx.collect());
104+
/// let received: Vec<i32> = rx.collect().await;
104105
/// assert_eq!(received, vec![42, 42, 42, 42, 42]);
106+
/// # });
105107
/// ```
106108
fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
107109
where F: FnMut(U) -> St,

futures-util/src/stream/iter.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ impl<I> Unpin for Iter<I> {}
1818
/// simply always calls `iter.next()` and returns that.
1919
///
2020
/// ```
21-
/// use futures::executor::block_on;
21+
/// #![feature(async_await)]
22+
/// # futures::executor::block_on(async {
2223
/// use futures::stream::{self, StreamExt};
2324
///
2425
/// let mut stream = stream::iter(vec![17, 19]);
25-
/// assert_eq!(vec![17, 19], block_on(stream.collect::<Vec<i32>>()));
26+
/// assert_eq!(vec![17, 19], stream.collect::<Vec<i32>>().await);
27+
/// # });
2628
/// ```
2729
pub fn iter<I>(i: I) -> Iter<I::IntoIter>
2830
where I: IntoIterator,

0 commit comments

Comments
 (0)