Skip to main content

mangofetch_core/core/
log_hook.rs

1use std::sync::{Arc, OnceLock};
2
3pub type LogSink = Arc<dyn Fn(u64, &str) + Send + Sync + 'static>;
4
5static SINK: OnceLock<LogSink> = OnceLock::new();
6
7pub fn set_log_sink(sink: LogSink) {
8    let _ = SINK.set(sink);
9}
10
11pub fn emit_log(id: u64, line: &str) {
12    if let Some(s) = SINK.get() {
13        s(id, line);
14    }
15}
16
17tokio::task_local! {
18    pub static CURRENT_DOWNLOAD_ID: u64;
19}
20
21pub fn current_download_id() -> Option<u64> {
22    CURRENT_DOWNLOAD_ID.try_with(|v| *v).ok()
23}