Skip to content

Commit

Permalink
oneshot: update closed() docs to use tokio::select! (#3050)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn committed Oct 26, 2020
1 parent 1c28c3b commit a9da220
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tokio/src/sync/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ impl<T> Sender<T> {
/// use tokio::sync::oneshot;
/// use tokio::time::{self, Duration};
///
/// use futures::{select, FutureExt};
///
/// async fn compute() -> String {
/// // Complex computation returning a `String`
/// # "hello".to_string()
Expand All @@ -297,12 +295,14 @@ impl<T> Sender<T> {
/// let (mut tx, rx) = oneshot::channel();
///
/// tokio::spawn(async move {
/// select! {
/// _ = tx.closed().fuse() => {
/// tokio::select! {
/// _ = tx.closed() => {
/// // The receiver dropped, no need to do any further work
/// }
/// value = compute().fuse() => {
/// tx.send(value).unwrap()
/// value = compute() => {
/// // The send can fail if the channel was closed at the exact same
/// // time as when compute() finished, so just ignore the failure.
/// let _ = tx.send(value);
/// }
/// }
/// });
Expand Down

0 comments on commit a9da220

Please sign in to comment.