zebra_scan/service/
scan_task.rs
1use std::sync::Arc;
4
5use color_eyre::Report;
6use tokio::task::JoinHandle;
7
8use zebra_state::ChainTipChange;
9
10use crate::storage::Storage;
11
12mod commands;
13mod executor;
14pub mod scan;
15
16pub use commands::ScanTaskCommand;
17
18#[cfg(any(test, feature = "proptest-impl"))]
19pub mod tests;
20
21#[derive(Debug, Clone)]
22pub struct ScanTask {
24 pub handle: Arc<JoinHandle<Result<(), Report>>>,
26
27 pub cmd_sender: tokio::sync::mpsc::Sender<ScanTaskCommand>,
29}
30
31const SCAN_TASK_BUFFER_SIZE: usize = 100;
33
34impl ScanTask {
35 pub fn spawn(db: Storage, state: scan::State, chain_tip_change: ChainTipChange) -> Self {
37 let (cmd_sender, cmd_receiver) = tokio::sync::mpsc::channel(SCAN_TASK_BUFFER_SIZE);
39
40 Self {
41 handle: Arc::new(scan::spawn_init(db, state, chain_tip_change, cmd_receiver)),
42 cmd_sender,
43 }
44 }
45}