From 135968d8f1379a6d2f32cbbc3e5b77a5f317a4d6 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Mon, 24 Jun 2024 02:18:03 +0200 Subject: p2p/examples: remove redundant code --- p2p/examples/monitor/src/shared.rs | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 p2p/examples/monitor/src/shared.rs (limited to 'p2p/examples/monitor/src/shared.rs') diff --git a/p2p/examples/monitor/src/shared.rs b/p2p/examples/monitor/src/shared.rs deleted file mode 100644 index 0e8079c..0000000 --- a/p2p/examples/monitor/src/shared.rs +++ /dev/null @@ -1,31 +0,0 @@ -use std::{num::NonZeroUsize, sync::Arc, thread}; - -use easy_parallel::Parallel; -use smol::{channel, future, future::Future, Executor}; - -/// Returns an estimate of the default amount of parallelism a program should use. -/// see `std::thread::available_parallelism` -pub fn available_parallelism() -> usize { - thread::available_parallelism() - .map(NonZeroUsize::get) - .unwrap_or(1) -} - -/// Run a multi-threaded executor -pub fn run_executor(main_future: impl Future, ex: Arc>) { - let (signal, shutdown) = channel::unbounded::<()>(); - - let num_threads = available_parallelism(); - - Parallel::new() - .each(0..(num_threads), |_| { - future::block_on(ex.run(shutdown.recv())) - }) - // Run the main future on the current thread. - .finish(|| { - future::block_on(async { - main_future.await; - drop(signal); - }) - }); -} -- cgit v1.2.3