INNER CODE UNIT · Rust

handle_progress_update

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

    fn handle_progress_update(&self, task_id: &str, update: ProgressUpdate) {
        // Progress events during the download loop do NOT persist to disk
        // (would cause disk thrash at 250ms intervals). We persist only on
        // state transitions and at completion.
        let persist = !matches!(update.state, DownloadTaskState::Downloading);

        if let Some(task) = self.get_task(task_id) {
            if let Ok(mut g) = task.lock() {
                let total = update.total_bytes;
                let bytes = update.bytes_downloaded;
                g.persisted.state = update.state.clone();
                g.persisted.bytes_downloaded = bytes;
                g.persisted.total_bytes = total;
                g.persisted.progress = total
                    .filter(|&t| t > 0)
                    .map(|t| (bytes as f64 / t as f64).clamp(0.0, 1.0))
                    .unwrap_or_else(|| match update.state {
                        DownloadTaskState::CompletedPendingAck => 1.0,

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…