-
Notifications
You must be signed in to change notification settings - Fork 881
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
Switch to stable futures #1196
Conversation
ff0aa9e
to
ba4e2f7
Compare
fd5f3d6
to
02d00cc
Compare
2cb77ec
to
c6adf00
Compare
1d940df
to
3c070ca
Compare
fe62305
to
ba7222e
Compare
If nobody is against this, let's merge this branch into the |
There was a problem hiding this 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> { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"] } |
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// 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"] } |
There was a problem hiding this comment.
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"] } |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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.
I'll address the review in a follow-up PR. |
* Switch to stable futures * Remove from_fn * Fix secio * Fix core --lib tests
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.
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.
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
andPoll
items it's not a problem, because the library re-exports these symbols from the Rust standard library. Therefore if a function returns aPoll
coming fromfutures-preview 0.3.0-alpha.17
, it is the samePoll
as the one infutures-preview 0.3.0-alpha.16
for example.For
Sink
,Stream
,AsyncRead
andAsyncWrite
, this is more problematic, and I hope that a version 0.3.0 offutures-preview
will be eventually released.cc #993