diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 99b849f..d679825 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -17,7 +17,7 @@ - [Connecting Readers and Writers](./tutorial/connecting_readers_and_writers.md) - [All Together](./tutorial/all_together.md) - [Clean Shutdown](./tutorial/clean_shutdown.md) - - [Handling Disconnections](./tutorial/handling_disconnections.md) + - [Handling Disconnection](./tutorial/handling_disconnection.md) - [Implementing a Client](./tutorial/implementing_a_client.md) - [TODO: Async Patterns](./patterns.md) - [TODO: Collected Small Patterns](./patterns/small-patterns.md) diff --git a/docs/src/tutorial/handling_disconnection.md b/docs/src/tutorial/handling_disconnection.md index 6c55a26..c7d91e5 100644 --- a/docs/src/tutorial/handling_disconnection.md +++ b/docs/src/tutorial/handling_disconnection.md @@ -58,6 +58,7 @@ We use `select` macro for this purpose: ```rust use futures::select; +use futures::FutureExt; async fn client_writer( messages: &mut Receiver, @@ -67,11 +68,11 @@ async fn client_writer( let mut stream = &*stream; loop { // 2 select! { - msg = messages.next() => match msg { + msg = messages.next().fuse() => match msg { Some(msg) => stream.write_all(msg.as_bytes()).await?, None => break, }, - void = shutdown.next() => match void { + void = shutdown.next().fuse() => match void { Some(void) => match void {}, // 3 None => break, } @@ -105,6 +106,7 @@ use std::{ use futures::{ channel::mpsc, SinkExt, + FutureExt, select, }; @@ -185,11 +187,11 @@ async fn client_writer( let mut stream = &*stream; loop { select! { - msg = messages.next() => match msg { + msg = messages.next().fuse() => match msg { Some(msg) => stream.write_all(msg.as_bytes()).await?, None => break, }, - void = shutdown.next() => match void { + void = shutdown.next().fuse() => match void { Some(void) => match void {}, None => break, } diff --git a/docs/src/tutorial/implementing_a_client.md b/docs/src/tutorial/implementing_a_client.md index 482f313..ec30db3 100644 --- a/docs/src/tutorial/implementing_a_client.md +++ b/docs/src/tutorial/implementing_a_client.md @@ -20,6 +20,7 @@ With async, we can just use the `select!` macro. use std::net::ToSocketAddrs; use futures::select; +use futures::FutureExt; use async_std::{ prelude::*, @@ -45,14 +46,14 @@ async fn try_main(addr: impl ToSocketAddrs) -> Result<()> { let mut lines_from_stdin = futures::StreamExt::fuse(stdin.lines()); // 2 loop { select! { // 3 - line = lines_from_server.next() => match line { + line = lines_from_server.next().fuse() => match line { Some(line) => { let line = line?; println!("{}", line); }, None => break, }, - line = lines_from_stdin.next() => match line { + line = lines_from_stdin.next().fuse() => match line { Some(line) => { let line = line?; writer.write_all(line.as_bytes()).await?;