1

The documentation for the tokio-tungstenite crate mostly just directs you to the examples section.

The client example hasn't been updated in a few years and I saw some unfamiliar async code here and because Rust's async APIs are still in flux I wanted to check the use futures_util::future::select was still idiomatic in this situation.

In particular, it seems to work fine if I replace it with the more commonly seen tokio::select! macro, which doesn't require pinning the passed futures.

I have good familiarity with tokio's APIs but not so much the lower level futures ones. Is there a reason to manually pin here and use the future::select instead? More generally, in modern idiomatic async Rust code when would one use the latter?

Sergio Gliesh
  • 329
  • 1
  • 2
  • 8

1 Answers1

1

It should be fine to replace any use of futures::future::select() with tokio::select! (or futures::select!). They both do the same thing. select! allow for more than one future, while select() gives you a named future. I prefer select! when I can (I think it is also more performant, but I'm not sure).

Chayim Friedman
  • 47,971
  • 5
  • 48
  • 77