[async] Help with implementing `future::Stream::poll_next` with multiple child streams

I've got an type with the following structure

struct MultiStream {
    s1: Receiver<()>,
    s2: Receiver<()>,
    // .. more receivers
}

To impl Stream for this type I need to implement poll_next. At the moment my strategy is to poll all streams, and if there are multiple successes, storing those temporarily so I can return Poll::Ready(Item) without doing any work on future iterations.

What I would love is something like select! but that worked on Poll rather than on futures.

Does anyone have any general advice?

It sounds like you're trying to reimplement SelectAll.

Urgh knew it would exist somewhere, thanks!

EDIT Hmm my use case is actually more complicated than the example I gave: I have a mixture of different types which return different Items, and some of my stream are actually futures (specifically a future that indicates a connection is closed, so there will be no more events on any of my streams). I think I'm going to have to roll something custom.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.