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

Remove wait on future in network bridge#1765

Merged
bkchr merged 7 commits into
paritytech:masterfrom
gterzian:remove_waits
Feb 12, 2019
Merged

Remove wait on future in network bridge#1765
bkchr merged 7 commits into
paritytech:masterfrom
gterzian:remove_waits

Conversation

@gterzian

Copy link
Copy Markdown
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
Comment thread core/finality-grandpa/src/lib.rs Outdated
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
if let Some(ref mut inner) = self.inner {
return inner
.poll()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Weird line break.

Comment thread core/finality-grandpa/src/lib.rs Outdated
return inner
.poll()
}
if let Ok(futures::Async::Ready(mut inner)) = self.outer.poll() {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread core/finality-grandpa/src/lib.rs Outdated
self.inner = Some(inner);
return poll_result
}
Ok(futures::Async::NotReady)

Copy link
Copy Markdown
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,
       }
    }
}

@gterzian gterzian Feb 12, 2019

Copy link
Copy Markdown
Contributor Author

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).

Comment thread core/finality-grandpa/src/lib.rs Outdated
Comment thread core/finality-grandpa/src/lib.rs Outdated
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>
Comment thread core/finality-grandpa/src/lib.rs Outdated
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