Skip to content

Comments

impl Future for stream::{Buffered, BufferUnordered, FuturesOrdered}#2677

Open
arcnmx wants to merge 2 commits intorust-lang:masterfrom
arcnmx:stream-buffer-poll
Open

impl Future for stream::{Buffered, BufferUnordered, FuturesOrdered}#2677
arcnmx wants to merge 2 commits intorust-lang:masterfrom
arcnmx:stream-buffer-poll

Conversation

@arcnmx
Copy link
Contributor

@arcnmx arcnmx commented Dec 18, 2022

This enables poll()ing to fill the buffer without producing or consuming the Stream's outputs.

Buffered and FuturesOrdered will also poll their inner futures produced by the stream, since they have an output value buffer available.
BufferUnordered however will only poll the underlying stream, as it cannot produce outputs without consuming them.

Given that the Output of the BufferUnordered impl isn't particularly useful (because it doesn't indicate anything about the futures produced by the stream), maybe it should be type Output = Infallible, and never complete?
For the other two, the completion is more meaningful as it indicates that the stream is empty and that all captured futures have produced outputs (though in the case of Buffered, it will stall while the buffer remains full).

It may also make sense to expose this as a poll_stream() function rather than impl Future (or otherwise a IntoFuture for &Self or something), for the sake of extension trait method resolution.

EDIT: moved to inherent poll_stream() instead, see latest commit. Final name tbd (buffered.poll_all()? poll_buffer()? poll_fill()?)

This enables `poll()`ing to fill the buffer without producing or
consuming the Stream's outputs.
@arcnmx arcnmx requested a review from taiki-e as a code owner December 18, 2022 20:25
@arcnmx arcnmx force-pushed the stream-buffer-poll branch from 3ffd896 to 94b6155 Compare December 18, 2022 23:28
@taiki-e
Copy link
Member

taiki-e commented Mar 5, 2023

Thanks for the PR. What is the use case for these methods?

@taiki-e taiki-e added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author label Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants