mina_node_testing/cluster/
p2p_task_spawner.rs1use mina_core::channels::Aborted;
2use node::{core::thread, p2p::service_impl::TaskSpawner};
3
4#[derive(Clone)]
5pub struct P2pTaskSpawner {
6 shutdown: Aborted,
7}
8
9impl P2pTaskSpawner {
10 pub fn new(shutdown: Aborted) -> Self {
11 Self { shutdown }
12 }
13}
14
15impl TaskSpawner for P2pTaskSpawner {
16 fn spawn_main<F>(&self, name: &str, fut: F)
17 where
18 F: 'static + Send + std::future::Future<Output = ()>,
19 {
20 let shutdown = self.shutdown.clone();
21 let runtime = tokio::runtime::Builder::new_current_thread()
22 .enable_all()
23 .build()
24 .unwrap();
25 thread::Builder::new()
26 .name(format!("mina_p2p_{name}"))
27 .spawn(move || {
28 let fut = async {
29 tokio::select! {
30 _ = shutdown.wait() => {}
31 _ = fut => {}
32 }
33 };
34 let local_set = tokio::task::LocalSet::new();
35 local_set.block_on(&runtime, fut);
36 })
37 .unwrap();
38 }
39}