mirror of
https://github.com/async-rs/async-std.git
synced 2025-02-06 04:35:32 +00:00
Book fixes
This commit is contained in:
parent
e8e82c6b71
commit
9b583b358a
3 changed files with 10 additions and 7 deletions
|
@ -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)
|
||||
|
|
|
@ -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<String>,
|
||||
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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?;
|
||||
|
|
Loading…
Reference in a new issue