Functioning download progress updates

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2024-11-04 17:11:37 +11:00
parent bd39f1fd72
commit 0528c78092
9 changed files with 89 additions and 27 deletions

View File

@ -1,23 +1,25 @@
use atomic_counter::RelaxedCounter;
use crate::downloads::progress::ProgressChecker;
use std::sync::atomic::{AtomicBool, AtomicUsize};
use std::sync::Arc;
#[test]
fn test_progress_sequentially() {
let counter = Arc::new(AtomicUsize::new(0));
let counter = Arc::new(RelaxedCounter::new(0));
let callback = Arc::new(AtomicBool::new(false));
let p = ProgressChecker::new(Box::new(test_fn), counter.clone(), callback);
let p = ProgressChecker::new(Box::new(test_fn), counter.clone(), callback, 100);
p.run_contexts_sequentially((1..100).collect());
println!("Progress: {}", p.get_progress_percentage(100));
println!("Progress: {}", p.get_progress_percentage());
}
#[test]
fn test_progress_parallel() {
let counter = Arc::new(AtomicUsize::new(0));
let counter = Arc::new(RelaxedCounter::new(0));
let callback = Arc::new(AtomicBool::new(false));
let p = ProgressChecker::new(Box::new(test_fn), counter.clone(), callback);
let p = ProgressChecker::new(Box::new(test_fn), counter.clone(), callback, 100);
p.run_contexts_parallel_background((1..100).collect(), 10);
}
fn test_fn(int: usize, callback: Arc<AtomicBool>) {
fn test_fn(int: usize, callback: Arc<AtomicBool>, counter: Arc<RelaxedCounter>) {
println!("{}", int);
}