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

Replace NetworkWorker::poll with NetworkWorker::next_action #5763

Closed
wants to merge 3 commits into from

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Apr 23, 2020

As a follow-up to that comment: #5704 (comment)

This opens the door for making the code async-awaitable in the future, without changing any behaviour right now.

polkadot companion: paritytech/polkadot#1029

@tomaka tomaka added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes labels Apr 23, 2020
@tomaka tomaka requested a review from mxinden April 23, 2020 16:13
impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
type Output = Result<(), io::Error>;
impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
/// Performs one action on the network, then returns.
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not quite sure I follow. If I read the logic below correctly this does not perform a single action, but block until the entire NetworkWorker is done.

Based on the pull request description I am guessing that this comment describes the behavior that we would like to have in the future. If so, would you mind mentioning that in the comment?


fn poll(mut self: Pin<&mut Self>, cx: &mut std::task::Context) -> Poll<Self::Output> {
/// Implementation of `next_action`. Note that this is not an implementation of `Future` but
Copy link
Contributor

Choose a reason for hiding this comment

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

As this is an implementation detail now, it could as well just implement future, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I precisely don't want NetworkWorker to implement Future, otherwise it's impossible to rewrite that as an async block.

@@ -1019,7 +1028,7 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
// Process the next message coming from the `NetworkService`.
let msg = match this.from_worker.poll_next_unpin(cx) {
Poll::Ready(Some(msg)) => msg,
Poll::Ready(None) => return Poll::Ready(Ok(())),
Poll::Ready(None) => return Poll::Ready(()),
Copy link
Contributor

Choose a reason for hiding this comment

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

This return Poll::Ready(()) is used to signal not to poll the NetworkWorker again.

You must call this method in a loop.

With this comment from above in mind one would still continue polling the NetworkWorker, right? Am I missing something?

@tomaka
Copy link
Contributor Author

tomaka commented May 4, 2020

Going to close this. I wanted to rush this before the stabilization because it's nicer, but we can do without.

@tomaka tomaka closed this May 4, 2020
@tomaka tomaka deleted the tka-smaller-version-of-5704 branch May 4, 2020 13:59
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. B0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants