[08_revisit_everything] add initial implementation

This commit is contained in:
2025-09-12 09:28:22 +02:00
parent f8563d118c
commit d54dfc15ec
2 changed files with 87 additions and 4 deletions

View File

@@ -9,7 +9,7 @@ use std::time::Instant;
const USER_NAME: &str = "Jonah";
pub fn compute_async<T: Display + Send + 'static, R: Send + 'static>(mut function: impl FnMut(Sender<(T, T)>) -> R + Send + 'static ) -> R {
pub fn compute_async<T1: Display + Send + 'static, T2: Display + Send + 'static, R: Send + 'static>(mut function: impl FnMut(Sender<(T1, T2)>) -> R + Send + 'static ) -> R {
let (tx, jh1) = spawn_submission_thread();
let jh2 = thread::spawn(move || {
function(tx)
@@ -19,8 +19,8 @@ pub fn compute_async<T: Display + Send + 'static, R: Send + 'static>(mut functio
jh2.join().unwrap()
}
pub fn spawn_submission_thread<T: Display + Send + 'static>() -> (Sender<(T, T)>, JoinHandle<()>) {
let (tx, rx) = mpsc::channel::<(T, T)>();
pub fn spawn_submission_thread<T1: Display + Send + 'static, T2: Display + Send + 'static>() -> (Sender<(T1, T2)>, JoinHandle<()>) {
let (tx, rx) = mpsc::channel::<(T1, T2)>();
let handle = thread::spawn(move || {
let mut t = Instant::now();
for (n, x) in rx {
@@ -37,7 +37,7 @@ pub fn spawn_submission_thread<T: Display + Send + 'static>() -> (Sender<(T, T)>
(tx, handle)
}
pub fn submit<T: Display + Send>(n: T, x: T) -> Result<Option<String>> {
pub fn submit<T1: Display + Send, T2: Display + Send>(n: T1, x: T2) -> Result<Option<String>> {
let url = format!("https://button.qedaka.de/server.php?name={USER_NAME}&n={n}&x={x}");
let body = reqwest::blocking::get(url)?.text()?;
match json::parse(&body)? {