Progress checker works

This commit is contained in:
quexeky
2024-10-18 20:42:26 +11:00
parent 31e794f637
commit f8b96d06e7
6 changed files with 98 additions and 11 deletions
+10 -9
View File
@@ -1,13 +1,9 @@
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::atomic::Ordering::Relaxed;
use crate::utils::ProgressChecker::Complete;
use rayon::{ThreadPool, ThreadPoolBuilder};
#[derive(Eq, PartialEq)]
pub enum ProgressChecker {
Complete,
Incomplete
}
/*
// This function is designed to take in any function which does not regularly return a value,
// and instead loops over it until it returns "Complete". The current number of iterations
// is counted by "progress"
@@ -18,16 +14,20 @@ pub async fn progress_updater(function: Box<dyn Fn() -> ProgressChecker>, progre
}
}
pub async fn new_progress_updater<T, D>(function: Box<dyn Fn(T) -> D>, contexts: T, progress: AtomicUsize) {
}
pub async fn threaded_progress_updater<F>(f: F, progress: AtomicUsize, max_threads: usize, instances: usize) -> ProgressChecker
where F: Fn() -> ProgressChecker + Send + Clone + Copy + 'static
{
let mut threads = Vec::new();
let pool = ThreadPoolBuilder::new().num_threads(max_threads).build().unwrap();
for instance in 0..instances {
let func = tokio::spawn(async move {
pool.spawn(move || -> ProgressChecker {
let res = f();
return res
});
threads.push(func);
}
let mut completed = ProgressChecker::Incomplete;
for thread in threads {
@@ -41,4 +41,5 @@ where F: Fn() -> ProgressChecker + Send + Clone + Copy + 'static
fn test() -> ProgressChecker {
ProgressChecker::Incomplete
}
}
*/