diff options
author | hozan23 <hozan23@karyontech.net> | 2024-06-24 02:18:03 +0200 |
---|---|---|
committer | hozan23 <hozan23@karyontech.net> | 2024-06-24 02:18:03 +0200 |
commit | 135968d8f1379a6d2f32cbbc3e5b77a5f317a4d6 (patch) | |
tree | 6de19fd08ccd1fa65846090f9b4346dff5fbbd54 /p2p/examples/monitor/src/shared.rs | |
parent | 06d3dd584641baa1877a261f533cdb6a30e311ad (diff) |
p2p/examples: remove redundant code
Diffstat (limited to 'p2p/examples/monitor/src/shared.rs')
-rw-r--r-- | p2p/examples/monitor/src/shared.rs | 31 |
1 files changed, 0 insertions, 31 deletions
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<T>(main_future: impl Future<Output = T>, ex: Arc<Executor<'_>>) { - 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); - }) - }); -} |