Hi everyone just started using Rust. I am trying to have a scanning bool be updated when a thread is finished without waiting for it to finish so my idea was to try and have the thread call and update_scanning on self but I have come across an issue maybe using Arc could help?
`self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
this data with an anonymous lifetime `'_`...
I am not really understanding this issue
use crate::db::get_connection;
use anyhow::Result;
use std::sync::{atomic::AtomicBool, Arc};
pub mod scanner;
pub mod tag_helper;
#[derive(Clone)]
pub struct Scanner {
scanning: AtomicBool,
}
impl Scanner {
pub fn new() -> Result<Scanner> {
let scanner = Scanner {
scanning: AtomicBool::new(false),
};
Ok(scanner)
}
fn update_scanning(&mut self, status: AtomicBool) {
self.scanning = status
}
pub fn get_status(&self) -> AtomicBool {
return self.scanning;
}
pub async fn start_scan(&mut self) {
tokio::spawn(async move {
let db_connection = get_connection().await.expect("Failed to connect to db");
use std::time::Instant;
let before = Instant::now();
scanner::walk(&db_connection).await.unwrap();
tracing::info!("Scan completed in: {:.2?}", before.elapsed());
self.update_scanning(AtomicBool::new(false))
//val = Arc::new(false);
});
}
}