Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Remove wait on future in network bridge #1765

Merged
merged 7 commits into from
Feb 12, 2019
Merged

Conversation

gterzian
Copy link
Contributor

Follow up on #1340 (comment)

@gterzian gterzian added the A0-please_review Pull request needs code review. label Feb 12, 2019
@gterzian gterzian requested a review from rphmeier February 12, 2019 06:00
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
if let Some(ref mut inner) = self.inner {
return inner
.poll()
Copy link
Member

Choose a reason for hiding this comment

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

Weird line break.

return inner
.poll()
}
if let Ok(futures::Async::Ready(mut inner)) = self.outer.poll() {
Copy link
Member

Choose a reason for hiding this comment

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

If the oneshot::Receiver is returning Error(Canceled), this will stuck forever.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How could we handle the error? An error would indicate network has shut down, and the entire system is likely shutting down. We could panic on an Err I guess...

Copy link
Member

Choose a reason for hiding this comment

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

I don't know what the error indicates. Maybe we should just throw Err(()).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can propagate an appropriate error.

self.inner = Some(inner);
return poll_result
}
Ok(futures::Async::NotReady)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe rewrite this whole function as:

loop {
    match self.inner {
        Some(ref mut inner) => return inner.poll(),
        None => match self.outer.poll() {
            Ok(Ready(inner)) => self.inner = Some(inner),
            Ok(NotReady) => return Ok(NotReady),
            Err(e) => handle the error,
       }
    }
}

Copy link
Contributor Author

@gterzian gterzian Feb 12, 2019

Choose a reason for hiding this comment

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

clever, and I'd rather rely on the next call to poll(or actually just do it in the same call to poll without the loop).

core/finality-grandpa/src/lib.rs Outdated Show resolved Hide resolved
core/finality-grandpa/src/lib.rs Outdated Show resolved Hide resolved
bkchr and others added 3 commits February 12, 2019 19:50
Co-Authored-By: gterzian <2792687+gterzian@users.noreply.github.com>
Co-Authored-By: gterzian <2792687+gterzian@users.noreply.github.com>
core/finality-grandpa/src/lib.rs Outdated Show resolved Hide resolved
Co-Authored-By: gterzian <2792687+gterzian@users.noreply.github.com>
@bkchr bkchr merged commit ca9537c into paritytech:master Feb 12, 2019
@gterzian gterzian deleted the remove_waits branch February 13, 2019 06:09
MTDK1 pushed a commit to bdevux/substrate that referenced this pull request Apr 12, 2019
* remove wait on future in network bridge

* nit

Co-Authored-By: gterzian <2792687+gterzian@users.noreply.github.com>

* nit

Co-Authored-By: gterzian <2792687+gterzian@users.noreply.github.com>

* nit

* propagate error

* nit once more

* nit

Co-Authored-By: gterzian <2792687+gterzian@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants