Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SinkExt::feed #2155

Merged
merged 2 commits into from
Dec 8, 2020
Merged

SinkExt::feed #2155

merged 2 commits into from
Dec 8, 2020

Conversation

mzabaluev
Copy link
Contributor

@mzabaluev mzabaluev commented May 14, 2020

Add SinkExt methods feed and feed_all. These are like send and send_all, except that the sink is not flushed at the end, allowing a sequence of output operations to be performed in async code without intermittent flushing. As a downside, the user is responsible for flushing or closing the sink to ensure completion.

Resolves #2059

@mzabaluev mzabaluev force-pushed the feed-the-sink branch 2 times, most recently from 3f30fbd to d82d0e8 Compare May 26, 2020 15:42
@Ekleog
Copy link

Ekleog commented Jun 11, 2020

@mzabaluev I've come here hoping for the same thing, but it looks like the CI build failed due to clippy warnings. Maybe that's why no one reviewed this yet?

If so, it looks like the clippy issues are probably not related to this PR, so hopefully just rebasing on latest master would fix the CI? :)

@mzabaluev
Copy link
Contributor Author

@Ekleog I have rebased and pushed the branch after some cleanup, but the CI situation is the same.

@Ekleog
Copy link

Ekleog commented Jun 11, 2020

Hmm that's weird, there's nothing in the diff that looks like it could be causing the raised issue… let's hope that someone with more knowledge of this repo comes and has a look, then, I guess :)

@taiki-e
Copy link
Member

taiki-e commented Jun 11, 2020

CI failure is due to (new) clippy bug: rust-lang/rust-clippy#5704

EDIT: will be fIxed in #2178

Copy link
Member

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay reviewing.

I think it makes sense to add feed method, but I'm not sure why feed_all method is needed. Could you explain the use case of feed_all? (IIUC, most of its use cases can be resolved with feed + loop or send_all, right?)

@mzabaluev
Copy link
Contributor Author

@taiki-e

Could you explain the use case of feed_all?

  1. For convenience of not having to read the source stream in a loop, in cases you want to send something more after the stream items without intermittent flushing;
  2. It's easy to extract from the code of SendAll, maintaining symmetry with Send/Feed.

@taiki-e
Copy link
Member

taiki-e commented Dec 8, 2020

Sorry for the delayed reply.

  • For convenience of not having to read the source stream in a loop, in cases you want to send something more after the stream items without intermittent flushing;
  • It's easy to extract from the code of SendAll, maintaining symmetry with Send/Feed.

These do not seem to benefit more than the confusion of providing similar methods with subtle differences. (Also, what this patch is trying to add is subtly different from feed + loop.)
We can consider accepting these implementation changes as a patch to send_all, in 0.4, but I don't think it's worth adding a new API (feed_all) for this.

Could you remove the changes related to feed_all? (If you want to discuss the addition of feed_all to 0.3, please open a new issue.)

@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 Dec 8, 2020
Like send, except no flushing is done at the end.
This allows sequentially feeding the sink with items in async code
without intermittent flushing.

Reuse code of Feed internally in the Send future.
@mzabaluev
Copy link
Contributor Author

mzabaluev commented Dec 8, 2020

Could you remove the changes related to feed_all? (If you want to discuss the addition of feed_all to 0.3, please open a new issue.)

I have pushed a rebased branch with just the changes for feed.

We can consider accepting these implementation changes as a patch to send_all, in 0.4

Is the plan to change the specification of send_all to not perform a complete flush at the end?
I think, for ease of use, it makes sense to retain the all-in-one method that's guaranteed to complete sending of all source items to the sink when the future it returns is resolved.

Also, what this patch is trying to add is subtly different from feed + loop.

This is actually part of why it makes sense to add as a method, just like send_all doing a more clever thing than send in a loop.

I will submit the send_all part in a separate PR.

@mzabaluev mzabaluev changed the title SinkExt::feed and SinkExt::feed_all SinkExt::feed Dec 8, 2020
@taiki-e
Copy link
Member

taiki-e commented Dec 8, 2020

Is the plan to change the specification of send_all to not perform a complete flush at the end?
I think, for ease of use, it makes sense to retain the all-in-one method that's guaranteed to complete sending of all source items to the sink when the future it returns is resolved.

I don't have any specific plans at this time, but I'm starting to think send_all doesn't necessarily have to do flush, given that write_all doesn't do flush.

(In any case, there are some issues in the current Sink trait, and in 0.4 the Sink trait itself may change.)

@taiki-e taiki-e removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author label Dec 8, 2020
@taiki-e taiki-e merged commit 440e74e into rust-lang:master Dec 8, 2020
@taiki-e
Copy link
Member

taiki-e commented Dec 8, 2020

Thanks!

@mzabaluev mzabaluev mentioned this pull request Dec 9, 2020
@taiki-e taiki-e mentioned this pull request Jan 8, 2021
@taiki-e taiki-e added the A-sink Area: futures::sink label Jan 11, 2021
exrook pushed a commit to exrook/futures-rs that referenced this pull request Apr 5, 2021
Like send, except no flushing is done at the end.
This allows sequentially feeding the sink with items in async code
without intermittent flushing.

Reuse code of Feed internally in the Send future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sink Area: futures::sink
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SinkExt::send without flushing
3 participants