Skip to content

Commit 9c03137

Browse files
authored
docs: add description for fuse() in handling_disconnection
Ref #88
1 parent 7560f0f commit 9c03137

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

docs/src/tutorial/handling_disconnection.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ async fn connection_writer_loop(
9090
let mut shutdown = shutdown.fuse();
9191
loop { // 2
9292
select! {
93-
msg = messages.next().fuse() => match msg {
93+
msg = messages.next().fuse() => match msg { // 3
9494
Some(msg) => stream.write_all(msg.as_bytes()).await?,
9595
None => break,
9696
},
9797
void = shutdown.next().fuse() => match void {
98-
Some(void) => match void {}, // 3
98+
Some(void) => match void {}, // 4
9999
None => break,
100100
}
101101
}
@@ -106,7 +106,8 @@ async fn connection_writer_loop(
106106

107107
1. We add shutdown channel as an argument.
108108
2. Because of `select`, we can't use a `while let` loop, so we desugar it further into a `loop`.
109-
3. In the shutdown case we use `match void {}` as a statically-checked `unreachable!()`.
109+
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.
110+
4. In the shutdown case we use `match void {}` as a statically-checked `unreachable!()`.
110111

111112
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.
112113
To not lose these messages completely, we'll return the messages channel back to the broker.

0 commit comments

Comments
 (0)