3 ms·
For the past seven years I've been urging people to stop using `select!` in async Rust code and use dedicated structured control flow primitives instead. Correc
by yoshuaw 7mo ago
For the past seven years I've been urging people to stop using `select!` in async Rust code and use dedicated structured control flow primitives instead. Correct use of `select!` cannot be guaranteed by the compiler [1], and so it's unsurprising it leads to bugs.
For the first example the better option would be to use the `race` operation [2]. For the second it would be better to use `ConcurrentStream` [3]. Many (but not all) of the issues people have with cancellation in async Rust can be improved with the advice: "don't use select!".
[1]: https://blog.yoshuawuyts.com/futures-concurrency-3/#issues-with-futures-select https://blog.yoshuawuyts.com/futures-concurrency-3/#issues-w...
[2]: https://docs.rs/futures-concurrency/latest/futures_concurrency/future/index.html https://docs.rs/futures-concurrency/latest/futures_concurren...
[3]: https://docs.rs/futures-concurrency/latest/futures_concurrency/concurrent_stream/index.html https://docs.rs/futures-concurrency/latest/futures_concurren...