INNER CODE UNIT · Rust

Ok

HemantKArya/BloomeeTunes · rust/src/api/downloader/mod.rs:594

        if let Ok(json) = serde_json::to_string_pretty(&tasks) {
            let _ = std::fs::create_dir_all(&self.state_dir);
            let _ = atomic_write(&self.manifest_path, json.as_bytes());
        }
    }
}

/// Safety net: `reqwest::blocking::Client` owns an internal tokio runtime.
/// When FRB drops the opaque `DownloadManager` it does so from an async
/// worker thread.  Dropping the runtime inside another runtime panics with
/// "Cannot drop a runtime in a context where blocking is not allowed."
///
/// If we hold the last `Arc` reference to the client **and** we are inside
/// a tokio context, move it to a plain OS thread for destruction.
impl Drop for DownloadManager {
    fn drop(&mut self) {
        if let Some(client) = self.http_client.take() {
            // Only the last Arc holder actually drops the inner Client.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…