Skip to content

Commit b7c7efc

Browse files
committed
Update try_channel doctests
1 parent 19fd7a4 commit b7c7efc

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

Diff for: src/sync/channel.rs

+21-13
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::sync::WakerSet;
3232
/// # Examples
3333
///
3434
/// ```
35+
/// # fn main() -> Result<(), async_std::sync::RecvError> {
3536
/// # async_std::task::block_on(async {
3637
/// #
3738
/// use std::time::Duration;
@@ -51,10 +52,11 @@ use crate::sync::WakerSet;
5152
/// });
5253
///
5354
/// task::sleep(Duration::from_secs(1)).await;
54-
/// assert_eq!(r.recv().await, Some(1));
55-
/// assert_eq!(r.recv().await, Some(2));
55+
/// assert_eq!(r.recv().await?, 1);
56+
/// assert_eq!(r.recv().await?, 2);
57+
/// # Ok(())
5658
/// #
57-
/// # })
59+
/// # }) }
5860
/// ```
5961
#[cfg(feature = "unstable")]
6062
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
@@ -113,6 +115,7 @@ impl<T> Sender<T> {
113115
/// # Examples
114116
///
115117
/// ```
118+
/// # fn main() -> Result<(), async_std::sync::RecvError> {
116119
/// # async_std::task::block_on(async {
117120
/// #
118121
/// use async_std::sync::channel;
@@ -125,11 +128,12 @@ impl<T> Sender<T> {
125128
/// s.send(2).await;
126129
/// });
127130
///
128-
/// assert_eq!(r.recv().await, Some(1));
129-
/// assert_eq!(r.recv().await, Some(2));
130-
/// assert_eq!(r.recv().await, None);
131+
/// assert_eq!(r.recv().await?, 1);
132+
/// assert_eq!(r.recv().await?, 2);
133+
/// assert!(r.recv().await.is_err());
131134
/// #
132-
/// # })
135+
/// # Ok(())
136+
/// # }) }
133137
/// ```
134138
pub async fn send(&self, msg: T) {
135139
struct SendFuture<'a, T> {
@@ -335,6 +339,7 @@ impl<T> fmt::Debug for Sender<T> {
335339
/// # Examples
336340
///
337341
/// ```
342+
/// # fn main() -> Result<(), async_std::sync::RecvError> {
338343
/// # async_std::task::block_on(async {
339344
/// #
340345
/// use std::time::Duration;
@@ -350,10 +355,11 @@ impl<T> fmt::Debug for Sender<T> {
350355
/// s.send(2).await;
351356
/// });
352357
///
353-
/// assert_eq!(r.recv().await, Some(1)); // Received immediately.
354-
/// assert_eq!(r.recv().await, Some(2)); // Received after 1 second.
358+
/// assert_eq!(r.recv().await?, 1); // Received immediately.
359+
/// assert_eq!(r.recv().await?, 2); // Received after 1 second.
355360
/// #
356-
/// # })
361+
/// # Ok(())
362+
/// # }) }
357363
/// ```
358364
#[cfg(feature = "unstable")]
359365
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
@@ -375,6 +381,7 @@ impl<T> Receiver<T> {
375381
/// # Examples
376382
///
377383
/// ```
384+
/// # fn main() -> Result<(), async_std::sync::RecvError> {
378385
/// # async_std::task::block_on(async {
379386
/// #
380387
/// use async_std::sync::channel;
@@ -388,11 +395,12 @@ impl<T> Receiver<T> {
388395
/// // Then we drop the sender
389396
/// });
390397
///
391-
/// assert_eq!(r.recv().await, Ok(1));
392-
/// assert_eq!(r.recv().await, Ok(2));
398+
/// assert_eq!(r.recv().await?, 1);
399+
/// assert_eq!(r.recv().await?, 2);
393400
/// assert!(r.recv().await.is_err());
394401
/// #
395-
/// # })
402+
/// # Ok(())
403+
/// # }) }
396404
/// ```
397405
pub async fn recv(&self) -> Result<T, RecvError> {
398406
struct RecvFuture<'a, T> {

0 commit comments

Comments
 (0)