3 ms·
Your favorite llm will give you several good options. You can use an mpsc channel where you have a task per sender which waits on each branch in the select and
by surajrmal 1y ago
Your favorite llm will give you several good options. You can use an mpsc channel where you have a task per sender which waits on each branch in the select and then sends a message and then just wait on the receiver end of that channel. Or you could use https://docs.rs/futures/latest/futures/future/fn.select.html https://docs.rs/futures/latest/futures/future/fn.select.html (or the select_all version). Both make it more obvious what is going on. The last way would be to implement a future manually. This would probably be my favorite option in many cases as it would be least overhead, but if you've never implemented a future it may be a bit intimidating.
Edit: tokio docs actually provide several suggestions: https://docs.rs/tokio/latest/tokio/macro.select.html#alternatives-from-the-ecosystem https://docs.rs/tokio/latest/tokio/macro.select.html#alterna...