Reading all messages from a websocket SplitStream #2022
-
Hey is there an easy way to read all messages that are currently in a SplitStream's stream e.g rcv.next().await until the stream is currently empty and then do something else? I cannot work out how to do this current e.g
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can read from the stream with https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html#method.next and if you wanna read for a few seconds you use combine it with https://docs.rs/tokio/latest/tokio/macro.select.html If you wanna read the whole stream and wait you can use https://docs.rs/futures/latest/futures/prelude/stream/trait.StreamExt.html#method.collect |
Beta Was this translation helpful? Give feedback.
You can read from the stream with https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html#method.next and if you wanna read for a few seconds you use combine it with https://docs.rs/tokio/latest/tokio/macro.select.html
If you wanna read the whole stream and wait you can use https://docs.rs/futures/latest/futures/prelude/stream/trait.StreamExt.html#method.collect