mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-16 10:49:55 +00:00
parent
7560f0fb90
commit
9c031375c8
1 changed files with 4 additions and 3 deletions
|
@ -90,12 +90,12 @@ async fn connection_writer_loop(
|
||||||
let mut shutdown = shutdown.fuse();
|
let mut shutdown = shutdown.fuse();
|
||||||
loop { // 2
|
loop { // 2
|
||||||
select! {
|
select! {
|
||||||
msg = messages.next().fuse() => match msg {
|
msg = messages.next().fuse() => match msg { // 3
|
||||||
Some(msg) => stream.write_all(msg.as_bytes()).await?,
|
Some(msg) => stream.write_all(msg.as_bytes()).await?,
|
||||||
None => break,
|
None => break,
|
||||||
},
|
},
|
||||||
void = shutdown.next().fuse() => match void {
|
void = shutdown.next().fuse() => match void {
|
||||||
Some(void) => match void {}, // 3
|
Some(void) => match void {}, // 4
|
||||||
None => break,
|
None => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,8 @@ async fn connection_writer_loop(
|
||||||
|
|
||||||
1. We add shutdown channel as an argument.
|
1. We add shutdown channel as an argument.
|
||||||
2. Because of `select`, we can't use a `while let` loop, so we desugar it further into a `loop`.
|
2. Because of `select`, we can't use a `while let` loop, so we desugar it further into a `loop`.
|
||||||
3. In the shutdown case we use `match void {}` as a statically-checked `unreachable!()`.
|
3. Function fuse() is used to turn any `Stream` into a `FusedStream`. This is used for fusing a stream such that poll_next will never again be called once it has finished.
|
||||||
|
4. In the shutdown case we use `match void {}` as a statically-checked `unreachable!()`.
|
||||||
|
|
||||||
Another problem is that between the moment we detect disconnection in `connection_writer_loop` and the moment when we actually remove the peer from the `peers` map, new messages might be pushed into the peer's channel.
|
Another problem is that between the moment we detect disconnection in `connection_writer_loop` and the moment when we actually remove the peer from the `peers` map, new messages might be pushed into the peer's channel.
|
||||||
To not lose these messages completely, we'll return the messages channel back to the broker.
|
To not lose these messages completely, we'll return the messages channel back to the broker.
|
||||||
|
|
Loading…
Reference in a new issue