chore: rm redundant pin (#8397)

This commit is contained in:
Matthias Seitz
2024-05-25 18:11:48 +02:00
committed by GitHub
parent 72f2f1b850
commit 50590aa18c
2 changed files with 13 additions and 12 deletions

View File

@ -53,7 +53,7 @@ use reth_tokio_util::EventSender;
use secp256k1::SecretKey;
use std::{
net::SocketAddr,
pin::{pin, Pin},
pin::Pin,
sync::{
atomic::{AtomicU64, AtomicUsize, Ordering},
Arc,
@ -895,25 +895,26 @@ where
{
/// Drives the [NetworkManager] future until a [GracefulShutdown] signal is received.
///
/// This also run the given function `shutdown_hook` afterwards.
pub async fn run_until_graceful_shutdown(
self,
/// This invokes the given function `shutdown_hook` while holding the graceful shutdown guard.
pub async fn run_until_graceful_shutdown<F, R>(
mut self,
shutdown: GracefulShutdown,
shutdown_hook: impl FnOnce(&mut Self),
) {
let network = self;
let mut network = pin!(network);
shutdown_hook: F,
) -> R
where
F: FnOnce(Self) -> R,
{
let mut graceful_guard = None;
tokio::select! {
_ = &mut network => {},
_ = &mut self => {},
guard = shutdown => {
graceful_guard = Some(guard);
},
}
shutdown_hook(&mut network);
let res = shutdown_hook(self);
drop(graceful_guard);
res
}
}

View File

@ -544,7 +544,7 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
"p2p network task",
|shutdown| {
network.run_until_graceful_shutdown(shutdown, |network| {
write_peers_to_file(network, known_peers_file)
write_peers_to_file(&network, known_peers_file)
})
},
);