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

Switch to stable futures #1196

Merged
merged 4 commits into from
Sep 16, 2019
Merged

Switch to stable futures #1196

merged 4 commits into from
Sep 16, 2019

Conversation

tomaka
Copy link
Member

@tomaka tomaka commented Jul 9, 2019

I'm opening this PR to show that I've started working on it, but it's nowhere close to being ready.
Considering that this is will force project which depend on rust-libp2p to upgrade to stable futures as well, we should maybe do a separate release just with this PR.

We're depending on futures-preview 0.3.0-alpha.17. It's not great to depend on such a version, because they aren't compatible with any other.

For the Future, Context and Poll items it's not a problem, because the library re-exports these symbols from the Rust standard library. Therefore if a function returns a Poll coming from futures-preview 0.3.0-alpha.17, it is the same Poll as the one in futures-preview 0.3.0-alpha.16 for example.

For Sink, Stream, AsyncRead and AsyncWrite, this is more problematic, and I hope that a version 0.3.0 of futures-preview will be eventually released.

cc #993

@tomaka tomaka force-pushed the new-futures branch 3 times, most recently from ff0aa9e to ba4e2f7 Compare July 9, 2019 15:58
@tomaka tomaka force-pushed the new-futures branch 10 times, most recently from fd5f3d6 to 02d00cc Compare July 14, 2019 20:03
@tomaka tomaka force-pushed the new-futures branch 16 times, most recently from 2cb77ec to c6adf00 Compare July 20, 2019 12:29
@tomaka tomaka force-pushed the new-futures branch 10 times, most recently from 1d940df to 3c070ca Compare September 4, 2019 14:08
@tomaka tomaka force-pushed the new-futures branch 3 times, most recently from fe62305 to ba7222e Compare September 11, 2019 09:48
@tomaka tomaka changed the base branch from master to stable-futures September 11, 2019 15:20
@tomaka tomaka marked this pull request as ready for review September 11, 2019 15:20
@tomaka
Copy link
Member Author

tomaka commented Sep 11, 2019

If nobody is against this, let's merge this branch into the stable-futures branch, despite the fact that it doesn't compile.
Then we will continue opening PRs against it to finish the changes.

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Just a basic pass. Comments can either be addressed here or with a follow up pull request. Both is fine by me.

I would suggest merging this branch (tomaka:new-futures) into libp2p/stable-futures. Once that happened all follow up new-future related changes can be merged into libp2p/stable-futures via pull requests, either being reviewed right away, or reviewed as a final pass over the entire libp2p/stable-futures branch before merging it into master.


#![cfg(feature = "async-await")]

pub struct FromFn<THandler> {
Copy link
Member

Choose a reason for hiding this comment

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

Is this file in work-in-progress state? Can you add some doc comments to understand the purpose of the file?

In case this is clear for anyone familiar with the codebase, please disregard my comment.

}

#[test]
fn listener_stream_returns_transport() {
Copy link
Member

Choose a reason for hiding this comment

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

Are all of these tests obsolete?

self.to_spawn.push(task);
let task = Box::pin(Task::new(task_id, self.events_tx.clone(), rx, future, handler));
if let Some(threads_pool) = &mut self.threads_pool {
threads_pool.spawn(task).expect("spawning a task on a threads pool never fails; qed");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
threads_pool.spawn(task).expect("spawning a task on a threads pool never fails; qed");
threads_pool.spawn(task).expect("spawning a task on a thread pool never fails; qed");


let task: Task<futures::future::Empty<_, _>, _, _, _, _, _, _> =
// TODO: we use `Pin<Box<Pending>>` instead of just `Pending` because `Pending` doesn't
Copy link
Member

Choose a reason for hiding this comment

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

Your patch should be included in futures-rs 0.3.0-alpha.18, right? What is stopping us from updating to 0.3.0-alpha.18?

@@ -136,40 +143,44 @@ where
// TODO: can be replaced with `impl Future` once `impl Trait` are fully stable in Rust
// (https://github.com/rust-lang/rust/issues/34511)
#[must_use = "futures do nothing unless polled"]
pub struct TokioTimerMapErr<InnerFut> {
pub struct Timeout<InnerFut> {
Copy link
Member

Choose a reason for hiding this comment

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

Why are we not using something like https://github.com/rustasync/futures-timer here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We are. The provided Timeout wrapper doesn't fit what we want though.

tokio-codec = "0.1"
tokio-io = "0.1"
unsigned-varint = { version = "0.2.1", features = ["codec"] }
unsigned-varint = { git = "https://github.com/tomaka/unsigned-varint", branch = "futures-codec", features = ["codec"] }
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a TODO here so we make sure we use either *unsigned-varint` with futures-codec, or unsigned-varint with an updated tokio-codec?

/// `Ready(Some())` is almost always returned. An error is returned if the stream is EOF.
fn next_match<C, F, O>(inner: &mut MultiplexInner<C>, mut filter: F) -> Poll<O, IoError>
where C: AsyncRead + AsyncWrite,
/// If `Pending` is returned, the waker is kept and notifier later, just like with any `Poll`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// If `Pending` is returned, the waker is kept and notifier later, just like with any `Poll`.
/// If `Pending` is returned, the waker is kept and notified later, just like with any `Poll`.

@@ -28,7 +28,7 @@ tokio-codec = "0.1"
tokio-io = "0.1"
wasm-timer = "0.1"
uint = "0.8"
unsigned-varint = { version = "0.2.1", features = ["codec"] }
unsigned-varint = { git = "https://github.com/tomaka/unsigned-varint", branch = "futures-codec", features = ["codec"] }
Copy link
Member

Choose a reason for hiding this comment

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

Same as above. Can you add a TODO so we make sure to clean this up?

sha2 = "0.8.0"
hmac = "0.7.0"
unsigned-varint = { git = "https://github.com/tomaka/unsigned-varint", branch = "futures-codec", features = ["codec"] }
Copy link
Member

Choose a reason for hiding this comment

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

Same as above. Can you add a TODO so we don't forget to clean this up?

type Item = Result<TBehaviour::OutEvent, io::Error>;

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
// We use a `this` variable to solve borrowing issues.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// We use a `this` variable to solve borrowing issues.
// We use a `this` variable because the compiler can't mutably borrow multiple times
// accross a `Deref`.

Let's keep these comments the same across the codebase so we can do an easy find-replace in case this can ever be solved in a prettier way.

@tomaka
Copy link
Member Author

tomaka commented Sep 16, 2019

I'll address the review in a follow-up PR.

@tomaka tomaka merged commit 170d2d2 into libp2p:stable-futures Sep 16, 2019
@tomaka tomaka deleted the new-futures branch September 16, 2019 09:13
@tomaka tomaka mentioned this pull request Sep 16, 2019
masonforest pushed a commit to masonforest/rust-libp2p that referenced this pull request Jan 7, 2020
* Switch to stable futures

* Remove from_fn

* Fix secio

* Fix core --lib tests
twittner added a commit to twittner/rust-libp2p that referenced this pull request Jul 30, 2020
Signal the end of stream as `None` instead of producing a broken pipe error.
This restores the behaviour prior to PR libp2p#1196. I could not find a motivation
for this particular change in the PR and the previous implementation looks
correct to me.
twittner added a commit that referenced this pull request Jul 31, 2020
Signal the end of stream as `None` instead of producing a broken pipe error.
This restores the behaviour prior to PR #1196. I could not find a motivation
for this particular change in the PR and the previous implementation looks
correct to me.
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.

None yet

2 participants