use tokio::sync::mpsc;
use crate::sources;
use crate::state::types::AurComment;
pub fn spawn_comments_worker(
mut comments_req_rx: mpsc::UnboundedReceiver<String>,
comments_res_tx: mpsc::UnboundedSender<(String, Result<Vec<AurComment>, String>)>,
) {
tokio::spawn(async move {
while let Some(pkgname) = comments_req_rx.recv().await {
let name = pkgname.clone();
match sources::fetch_aur_comments(pkgname).await {
Ok(comments) => {
let _ = comments_res_tx.send((name, Ok(comments)));
}
Err(e) => {
let _ =
comments_res_tx.send((name, Err(format!("Failed to fetch comments: {e}"))));
}
}
}
});
}