-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Replace NetworkWorker::poll with NetworkWorker::next_action #5763
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,7 @@ use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnbound | |
| use std::{ | ||
| borrow::Cow, | ||
| collections::HashSet, | ||
| fs, io, | ||
| fs, | ||
| marker::PhantomData, | ||
| pin::Pin, | ||
| str, | ||
|
|
@@ -991,10 +991,17 @@ impl Metrics { | |
| } | ||
| } | ||
|
|
||
| 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. | ||
| /// | ||
| /// The returned future is designed to be freely cancellable. | ||
| pub async fn next_action(&mut self) { | ||
| future::poll_fn(move |cx| Pin::new(&mut *self).poll(cx)).await | ||
| } | ||
|
|
||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I precisely don't want |
||
| /// a regular method. | ||
| fn poll(mut self: Pin<&mut Self>, cx: &mut std::task::Context) -> Poll<()> { | ||
| let this = &mut *self; | ||
|
|
||
| // Poll the import queue for actions to perform. | ||
|
|
@@ -1019,7 +1026,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(()), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
With this comment from above in mind one would still continue polling the |
||
| Poll::Pending => break, | ||
| }; | ||
|
|
||
|
|
||
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.
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
NetworkWorkeris 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?