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

Remove AwaitCanceled #1375

Merged
merged 3 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sc-network = { git = "https://github.com/paritytech/substrate", branch = "master
sc-network-gossip = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
futures = "0.3.4"
futures = "0.3.5"
log = "0.4.8"
exit-future = "0.2.0"
futures-timer = "2.0"
Expand Down
26 changes: 2 additions & 24 deletions network/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,28 +395,6 @@ struct ConsensusNetworkingInstance {
_drop_signal: exit_future::Signal,
}

/// A utility future that resolves when the receiving end of a channel has hung up.
///
/// This is an `.await`-friendly interface around `poll_canceled`.
// TODO: remove in favor of https://github.com/rust-lang/futures-rs/pull/2092/
// once published.
#[must_use = "futures do nothing unless you `.await` or poll them"]
#[derive(Debug)]
pub struct AwaitCanceled<'a, T> {
inner: &'a mut oneshot::Sender<T>,
}

impl<T> Future for AwaitCanceled<'_, T> {
type Output = ();

fn poll(
mut self: Pin<&mut Self>,
cx: &mut futures::task::Context<'_>,
) -> futures::task::Poll<()> {
self.inner.poll_canceled(cx)
}
}

/// Protocol configuration.
#[derive(Default)]
pub struct Config {
Expand Down Expand Up @@ -933,7 +911,7 @@ impl<Api, Sp, Gossip> Worker<Api, Sp, Gossip> where
let get_msg = fetch_pov_from_gossip(&candidate, &self.gossip_handle);

let _ = self.executor.spawn(async move {
let res = future::select(get_msg, AwaitCanceled { inner: &mut sender }).await;
let res = future::select(get_msg, sender.cancellation()).await;
if let Either::Left((pov_block, _)) = res {
let _ = sender.send(pov_block);
}
Expand Down Expand Up @@ -964,7 +942,7 @@ impl<Api, Sp, Gossip> Worker<Api, Sp, Gossip> where
));

let _ = self.executor.spawn(async move {
let res = future::select(get_msg, AwaitCanceled { inner: &mut sender }).await;
let res = future::select(get_msg, sender.cancellation()).await;
if let Either::Left((chunk, _)) = res {
let _ = sender.send(chunk);
}
Expand Down