add return value to compute_async

This commit is contained in:
2025-09-10 11:41:24 +02:00
parent d03584e8b6
commit 8cf5a8a9b4

View File

@@ -9,14 +9,14 @@ use std::time::Instant;
const USER_NAME: &str = "Jonah"; const USER_NAME: &str = "Jonah";
pub fn compute_async<T: Display + Send + 'static>(mut function: impl FnMut(Sender<(T, T)>) + Send + 'static) { pub fn compute_async<T: Display + Send + 'static, R: Send + 'static>(mut function: impl FnMut(Sender<(T, T)>) -> R + Send + 'static ) -> R {
let (tx, jh1) = spawn_submission_thread(); let (tx, jh1) = spawn_submission_thread();
let jh2 = thread::spawn(move || { let jh2 = thread::spawn(move || {
function(tx); function(tx)
}); });
jh1.join().unwrap(); jh1.join().unwrap();
jh2.join().unwrap(); jh2.join().unwrap()
} }
pub fn spawn_submission_thread<T: Display + Send + 'static>() -> (Sender<(T, T)>, JoinHandle<()>) { pub fn spawn_submission_thread<T: Display + Send + 'static>() -> (Sender<(T, T)>, JoinHandle<()>) {