1use crate::Config;
2use fuel_core_interfaces::{
3 block_importer::ImportBlockMpsc,
4 p2p::{
5 BlockGossipData,
6 P2pRequestEvent,
7 },
8 sync::SyncMpsc,
9};
10use parking_lot::Mutex;
11use tokio::{
12 sync::mpsc,
13 task::JoinHandle,
14};
15
16pub struct Service {
17 join: Mutex<Option<JoinHandle<()>>>,
18 sender: mpsc::Sender<SyncMpsc>,
19}
20
21impl Service {
22 pub async fn new(_config: &Config) -> anyhow::Result<Self> {
23 let (sender, _receiver) = mpsc::channel(100);
24 Ok(Self {
25 sender,
26 join: Mutex::new(None),
27 })
28 }
29
30 pub async fn start(
31 &self,
32 _p2p_block: mpsc::Receiver<BlockGossipData>,
33 _p2p_request: mpsc::Sender<P2pRequestEvent>,
34 _block_importer: mpsc::Sender<ImportBlockMpsc>,
37 ) {
38 let mut join = self.join.lock();
39 if join.is_none() {
40 *join = Some(tokio::spawn(async {}));
41 }
42 }
43
44 pub async fn stop(&self) -> Option<JoinHandle<()>> {
45 let join = self.join.lock().take();
46 if join.is_some() {
47 let _ = self.sender.send(SyncMpsc::Stop);
48 }
49 join
50 }
51
52 pub fn sender(&self) -> &mpsc::Sender<SyncMpsc> {
53 &self.sender
54 }
55}