MCPcopy Create free account
hub / github.com/Moosync/Moosync / spawn_scan_task

Method spawn_scan_task

src-tauri/src/scanner/mod.rs:48–77  ·  view source on GitHub ↗
(&self, app: AppHandle, scan_duration_s: u64)

Source from the content-addressed store, hash-verified

46
47impl ScanTask {
48 pub fn spawn_scan_task(&self, app: AppHandle, scan_duration_s: u64) {
49 {
50 let mut cancellation_token = self.cancellation_token.lock().unwrap();
51 if let Some(cancellation_token) = cancellation_token.as_mut() {
52 cancellation_token.store(true, std::sync::atomic::Ordering::Release);
53 }
54 }
55
56 let cancellation_token = Arc::new(AtomicBool::new(false));
57 let cancellation_token_inner = Arc::clone(&cancellation_token);
58
59 thread::spawn(move || loop {
60 thread::sleep(Duration::from_secs(scan_duration_s));
61
62 tracing::info!("Running scan task - {}s", scan_duration_s);
63 if cancellation_token_inner.load(std::sync::atomic::Ordering::Acquire) {
64 tracing::info!("Scan task cancelled - {}s", scan_duration_s);
65 break;
66 }
67
68 let app = app.clone();
69 let res = start_scan(app, None);
70 if let Err(e) = res {
71 tracing::error!("Scan failed: {:?}", e);
72 }
73 });
74
75 let mut cancellation_token_lock = self.cancellation_token.lock().unwrap();
76 *cancellation_token_lock = Some(cancellation_token);
77 }
78}
79
80#[tracing::instrument(level = "debug", skip(app, paths))]

Callers 2

handle_pref_changesFunction · 0.80
initialFunction · 0.80

Calls 3

start_scanFunction · 0.85
cloneMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected