oneshot: update closed() docs to use tokio::select! (#3050)

This commit is contained in:
Alice Ryhl 2020-10-26 11:44:46 +01:00 committed by GitHub
parent 1c28c3b0a8
commit a9da220923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -285,8 +285,6 @@ impl<T> Sender<T> {
/// use tokio::sync::oneshot; /// use tokio::sync::oneshot;
/// use tokio::time::{self, Duration}; /// use tokio::time::{self, Duration};
/// ///
/// use futures::{select, FutureExt};
///
/// async fn compute() -> String { /// async fn compute() -> String {
/// // Complex computation returning a `String` /// // Complex computation returning a `String`
/// # "hello".to_string() /// # "hello".to_string()
@ -297,12 +295,14 @@ impl<T> Sender<T> {
/// let (mut tx, rx) = oneshot::channel(); /// let (mut tx, rx) = oneshot::channel();
/// ///
/// tokio::spawn(async move { /// tokio::spawn(async move {
/// select! { /// tokio::select! {
/// _ = tx.closed().fuse() => { /// _ = tx.closed() => {
/// // The receiver dropped, no need to do any further work /// // The receiver dropped, no need to do any further work
/// } /// }
/// value = compute().fuse() => { /// value = compute() => {
/// tx.send(value).unwrap() /// // 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);
/// } /// }
/// } /// }
/// }); /// });