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

Allow !Unpin Sinks in Forward combinator #1441

Merged
merged 4 commits into from
Feb 27, 2019

Conversation

ebkalderon
Copy link
Contributor

@ebkalderon ebkalderon commented Jan 28, 2019

Changed

  • Update Forward so it drops the sink without returning it. Users wishing to access the sink again can pass a &mut sink to StreamExt::forward().
  • Update docs for both Forward and StreamExt::forward().

Removed

  • Remove requirement for Unpin sinks on Forward.

Fixes #1440. /CC @Nemo157.

Copy link
Member

@Nemo157 Nemo157 left a comment

Choose a reason for hiding this comment

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

LGTM.

We discussed changing Forward to drop the sink on completion instead of returning it on Discord, I feel it better fits the design of the 0.3 combinators (passing a sink by-ref in an async fn if necessary), and helps with cases where you accidentally keep it alive longer than you mean to (like the fanout test does, causing the timeout on the first commit).

@ebkalderon ebkalderon changed the title Fix StreamExt::forward impl by calling poll_flush() Fix StreamExt::forward impl, redesign Forward Jan 28, 2019
@ebkalderon
Copy link
Contributor Author

@cramertj Any particular thoughts on this change to the API?

@cramertj
Copy link
Member

It seems like maybe we should require passing Pin<&mut impl Sink> rather than taking a sink by-value, since the default behavior of forwarding and then dropping without closing will always be wrong (right?).

@Nemo157
Copy link
Member

Nemo157 commented Jan 29, 2019

Another alternative would be to just update the documentation to say this will close the provided Sink once the Stream is complete (and fix the mpsc::Sender to not kill the whole channel when closed like it currently does). You could then use something like an unclosable adaptor on a Sink that just flushes but doesn't actually close it if you want to keep it active after using forward.

@ebkalderon
Copy link
Contributor Author

@Nemo157 That sounds like a good idea. I can update the documentation, if you would like. Could you please elaborate on what you have in mind with an uncloseable adapter? Would this be another combinator we would add to the SinkExt trait?

@ebkalderon
Copy link
Contributor Author

Another thing to note: if we do not need to return the sink directly from Forward, we can also remove the Unpin sink requirement mentioned here.

@Nemo157
Copy link
Member

Nemo157 commented Jan 30, 2019

I've started the mpsc changes in #1443.

The uncloseable adaptor would just wrap a sink and call poll_flush from its poll_close, so once the adaptor was closed the underlying sink would be flushed but left open, you could then use it like

let mut sink = foo();
await!(stream.forward(sink.by_ref().dont_close()))?;
await!(sink.send(some_final_item))?;
await!(sink.close())?;

@ebkalderon
Copy link
Contributor Author

Sounds good! I've just pushed some commits updating the Forward docs and removing the Unpin sink bound as well. I would appreciate a soundness review of my changes here.

@ebkalderon
Copy link
Contributor Author

Pinging @cramertj @Nemo157. Do the docs and the removal of the Unpin sink bound from the last two commits look correct to you?

futures-util/src/stream/forward.rs Outdated Show resolved Hide resolved
futures-util/src/stream/forward.rs Outdated Show resolved Hide resolved
ebkalderon added a commit to ebkalderon/futures-rs that referenced this pull request Feb 15, 2019
@ebkalderon
Copy link
Contributor Author

@cramertj @Nemo157 Now that #1443 has been merged, I've updated my PR to switch back to using poll_close() over poll_flush(), and I have confirmed that the example code between 0.3.0 and 0.1.25 now behaves correctly. Ready for review again!

@ebkalderon
Copy link
Contributor Author

Interesting, futures-core-preview no longer compiles on some toolchains after my rebase. Will need to look into it further.

@Nemo157
Copy link
Member

Nemo157 commented Feb 15, 2019

That’s #1453, there are new changes in nightly that are waiting on #1445

@ebkalderon
Copy link
Contributor Author

Ah, yes. I just noticed this as well when trying to navigate to std::task::LocalWaker on the Rust API docs page and it wasn't found. Standing by until #1445 gets merged.

@ebkalderon
Copy link
Contributor Author

@cramertj @Nemo157 Awesome, looks like CI passes again thanks to #1445 being merged. 🎉 Anyone available for a final review of this PR?

@cramertj cramertj changed the title Fix StreamExt::forward impl, redesign Forward Allow !Unpin Sinks in Forward combinator Feb 22, 2019
@cramertj
Copy link
Member

LGTM-- would you mind flattening your commits to remove the previous changes to Forward that have since been removed?

@ebkalderon
Copy link
Contributor Author

@cramertj Okay, I've flattened away the redundant commits! I hope the commit history looks satisfactory now.

@cramertj
Copy link
Member

Thanks!

@cramertj cramertj merged commit 7d04778 into rust-lang:master Feb 27, 2019
@ebkalderon ebkalderon deleted the fix-stream-forward-impl branch February 28, 2019 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants