Implement futures_core::stream::Stream

I'm trying to implement poll_next for for a struct that communicates over a web socket (tokio_tungstenite).

The challenge I have is, to produce one message for my app, I need to consume two or more messages over the websocket.

For the first web socket message I can simply call poll_next on the web socket, and if it doesn't return an item, return pending.

What I can't figure out is how to wait for the following messages, i.e. my code may have to make several calls to the web socket poll_next before I can return a message.

It would be awesome if anyone has done this or could point me to some code that does something similar.

I find this super useful for implementing Stream, because I don't need to implement any polling and can write basic async code instead:

Writing poll_* methods manually can in some cases be very difficult, and I definitely recommend going for the async-stream crate unless you have good reasons for avoiding it.

If you are still interested in poll_* methods, there is a rough introduction to the internals of async/await in this chapter, along with a Stream example in the stream chapter.

Thank you both, I'll definitely check out the async-stream crate!!