From 95bddb12ca2f9204bdb335cea865ec81342bb6dd Mon Sep 17 00:00:00 2001 From: LukeMathWalker <20745048+LukeMathWalker@users.noreply.github.com> Date: Thu, 16 May 2024 13:17:59 +0200 Subject: [PATCH] Add StreamExt::merge --- book/src/08_futures/07_cancellation.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/book/src/08_futures/07_cancellation.md b/book/src/08_futures/07_cancellation.md index 557aa72..70c1954 100644 --- a/book/src/08_futures/07_cancellation.md +++ b/book/src/08_futures/07_cancellation.md @@ -102,6 +102,8 @@ async fn run() { - Be extremely careful when using `tokio`'s `select!` macro to "race" two different futures. Retrying the same task in a loop is dangerous unless you can ensure **cancellation safety**. - Check out [`select!`'s documentation](https://docs.rs/tokio/macro.select.html) for more details. + Check out [`select!`'s documentation](https://docs.rs/tokio/macro.select.html) for more details. + If you need to interleave two asynchronous streams of data (e.g. a socket and a channel), prefer using + [`StreamExt::merge`](https://docs.rs/tokio-stream/latest/tokio_stream/trait.StreamExt.html#method.merge) instead. - Rather than "abrupt" cancellation, it can be preferable to rely on [`CancellationToken`](https://docs.rs/tokio-util/latest/tokio_util/sync/struct.CancellationToken.html). \ No newline at end of file