mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-15 09:11:28 +10:00
Functioning download progress updates
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user