From 4a45e2ae304f6e51ce71a80ea92634f6c5502772 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Fri, 27 Jun 2025 10:19:03 -0700 Subject: [PATCH 1/9] remove more path/method re-setting --- hyperprocess_macro/src/lib.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/hyperprocess_macro/src/lib.rs b/hyperprocess_macro/src/lib.rs index 5a679bc..d5366e5 100644 --- a/hyperprocess_macro/src/lib.rs +++ b/hyperprocess_macro/src/lib.rs @@ -1309,18 +1309,8 @@ fn generate_message_handlers( let handler_body = if handler.is_async { quote! { // Capture context values before async execution - let current_path = hyperware_app_common::get_path(); - let current_method = hyperware_app_common::get_http_method(); - let state_ptr: *mut #self_ty = state; hyperware_app_common::hyper! { - // Restore context in the async task - hyperware_app_common::APP_HELPERS.with(|ctx| { - let mut ctx_mut = ctx.borrow_mut(); - ctx_mut.current_path = current_path; - ctx_mut.current_http_method = current_method; - }); - let result = unsafe { (*state_ptr).#fn_name().await }; #response_handling } From 7a645c560ff959c634e7d7f5fa2d8c04443a2a55 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Fri, 27 Jun 2025 10:23:58 -0700 Subject: [PATCH 2/9] remove un-setting current_path --- hyperprocess_macro/src/lib.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/hyperprocess_macro/src/lib.rs b/hyperprocess_macro/src/lib.rs index d5366e5..63ec9bc 100644 --- a/hyperprocess_macro/src/lib.rs +++ b/hyperprocess_macro/src/lib.rs @@ -1252,10 +1252,6 @@ fn generate_message_handlers( format!("Handler {} requires a request body", stringify!(#fn_name)).into_bytes() ); } - - hyperware_app_common::APP_HELPERS.with(|ctx| { - ctx.borrow_mut().current_path = None; - }); return; } } @@ -1330,9 +1326,6 @@ fn generate_message_handlers( if #path_check && #method_check { hyperware_process_lib::logging::debug!("Matched parameter-less handler {} for {} {}", stringify!(#fn_name), http_method, current_path); #handler_body - hyperware_app_common::APP_HELPERS.with(|ctx| { - ctx.borrow_mut().current_path = None; - }); return; } } @@ -1408,9 +1401,6 @@ fn generate_message_handlers( #http_request_match_arms hyperware_app_common::maybe_save_state(&mut *state); } - hyperware_app_common::APP_HELPERS.with(|ctx| { - ctx.borrow_mut().current_path = None; - }); return; }, Err(e) => { @@ -1436,9 +1426,6 @@ fn generate_message_handlers( None, error_details.into_bytes() ); - hyperware_app_common::APP_HELPERS.with(|ctx| { - ctx.borrow_mut().current_path = None; - }); return; } } @@ -1456,9 +1443,6 @@ fn generate_message_handlers( None, format!("No handler found for {} {}", http_method, current_path).into_bytes(), ); - hyperware_app_common::APP_HELPERS.with(|ctx| { - ctx.borrow_mut().current_path = None; - }); }, hyperware_process_lib::http::server::HttpServerRequest::WebSocketPush { channel_id, message_type } => { hyperware_process_lib::logging::debug!("Received WebSocket message on channel {}, type: {:?}", channel_id, message_type); From cdd0e82c1969ff7d49f4c032544a06c4ce22a1b6 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 30 Jun 2025 08:24:18 -0700 Subject: [PATCH 3/9] add sleep() --- hyperware_app_common/src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hyperware_app_common/src/lib.rs b/hyperware_app_common/src/lib.rs index a9b894f..c098dcd 100644 --- a/hyperware_app_common/src/lib.rs +++ b/hyperware_app_common/src/lib.rs @@ -9,7 +9,7 @@ use futures_util::task::noop_waker_ref; use hyperware_process_lib::http::server::HttpServer; use hyperware_process_lib::logging::info; use hyperware_process_lib::{ - get_state, http, kiprintln, set_state, BuildError, LazyLoadBlob, Message, Request, SendError, + get_state, http, kiprintln, set_state, timer, BuildError, LazyLoadBlob, Message, Request, SendError, }; use serde::Deserialize; use serde::Serialize; @@ -186,6 +186,14 @@ pub enum AppSendError { BuildError(BuildError), } +pub async fn sleep(sleep_ms: u64) -> Result<(), AppSendError> { + let timer_request = Request::to("our@timer:distro:sys") + .body(timer::TimerAction(sleep_ms)) + .expects_response((sleep_ms / 1_000) + 1); + + send(timer_request) +} + pub async fn send(request: Request) -> Result where R: serde::de::DeserializeOwned, From 8d314c7ba06297cf6a0c60e73b516aee46aa0a06 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 30 Jun 2025 08:26:16 -0700 Subject: [PATCH 4/9] await the send in sleep --- hyperware_app_common/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperware_app_common/src/lib.rs b/hyperware_app_common/src/lib.rs index c098dcd..19ac1f7 100644 --- a/hyperware_app_common/src/lib.rs +++ b/hyperware_app_common/src/lib.rs @@ -191,7 +191,7 @@ pub async fn sleep(sleep_ms: u64) -> Result<(), AppSendError> { .body(timer::TimerAction(sleep_ms)) .expects_response((sleep_ms / 1_000) + 1); - send(timer_request) + send(timer_request).await } pub async fn send(request: Request) -> Result From 2f0c914222304a20d165c3e1685bf29ccdc42064 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 30 Jun 2025 08:28:46 -0700 Subject: [PATCH 5/9] fix action & target --- hyperware_app_common/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hyperware_app_common/src/lib.rs b/hyperware_app_common/src/lib.rs index 19ac1f7..08a59b7 100644 --- a/hyperware_app_common/src/lib.rs +++ b/hyperware_app_common/src/lib.rs @@ -187,8 +187,8 @@ pub enum AppSendError { } pub async fn sleep(sleep_ms: u64) -> Result<(), AppSendError> { - let timer_request = Request::to("our@timer:distro:sys") - .body(timer::TimerAction(sleep_ms)) + let timer_request = Request::to(("our", "timer", "distro", "sys")) + .body(timer::TimerAction::SetTimer(sleep_ms)) .expects_response((sleep_ms / 1_000) + 1); send(timer_request).await From 67a351208fc9e08a1af020eb66ed2bb455a3dd09 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 30 Jun 2025 08:54:36 -0700 Subject: [PATCH 6/9] sleep: fix return type --- hyperware_app_common/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hyperware_app_common/src/lib.rs b/hyperware_app_common/src/lib.rs index 08a59b7..157d94e 100644 --- a/hyperware_app_common/src/lib.rs +++ b/hyperware_app_common/src/lib.rs @@ -191,7 +191,9 @@ pub async fn sleep(sleep_ms: u64) -> Result<(), AppSendError> { .body(timer::TimerAction::SetTimer(sleep_ms)) .expects_response((sleep_ms / 1_000) + 1); - send(timer_request).await + send(timer_request).await?; + + return Ok(()); } pub async fn send(request: Request) -> Result From 2f1af9e9ddfc0dac782998b0babc09dd4c74eebe Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 30 Jun 2025 09:00:48 -0700 Subject: [PATCH 7/9] try to fix deserialization --- hyperware_app_common/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperware_app_common/src/lib.rs b/hyperware_app_common/src/lib.rs index 157d94e..b97953c 100644 --- a/hyperware_app_common/src/lib.rs +++ b/hyperware_app_common/src/lib.rs @@ -191,7 +191,7 @@ pub async fn sleep(sleep_ms: u64) -> Result<(), AppSendError> { .body(timer::TimerAction::SetTimer(sleep_ms)) .expects_response((sleep_ms / 1_000) + 1); - send(timer_request).await?; + let _: Vec = send(timer_request).await?; return Ok(()); } From 1edd7dcbdf14243e7685390b688b1f5133207301 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 30 Jun 2025 09:08:28 -0700 Subject: [PATCH 8/9] do repeat yourself --- hyperware_app_common/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hyperware_app_common/src/lib.rs b/hyperware_app_common/src/lib.rs index b97953c..5df1e1f 100644 --- a/hyperware_app_common/src/lib.rs +++ b/hyperware_app_common/src/lib.rs @@ -191,7 +191,12 @@ pub async fn sleep(sleep_ms: u64) -> Result<(), AppSendError> { .body(timer::TimerAction::SetTimer(sleep_ms)) .expects_response((sleep_ms / 1_000) + 1); - let _: Vec = send(timer_request).await?; + let correlation_id = Uuid::new_v4().to_string(); + if let Err(e) = request.context(correlation_id.as_bytes().to_vec()).send() { + return Err(AppSendError::BuildError(e)); + } + + let _ = ResponseFuture::new(correlation_id).await; return Ok(()); } From 7fc30e01caece399b61581c1c92f3e0e3b4b9e13 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 30 Jun 2025 09:11:27 -0700 Subject: [PATCH 9/9] fix typo --- hyperware_app_common/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperware_app_common/src/lib.rs b/hyperware_app_common/src/lib.rs index 5df1e1f..4f81abf 100644 --- a/hyperware_app_common/src/lib.rs +++ b/hyperware_app_common/src/lib.rs @@ -187,7 +187,7 @@ pub enum AppSendError { } pub async fn sleep(sleep_ms: u64) -> Result<(), AppSendError> { - let timer_request = Request::to(("our", "timer", "distro", "sys")) + let request = Request::to(("our", "timer", "distro", "sys")) .body(timer::TimerAction::SetTimer(sleep_ms)) .expects_response((sleep_ms / 1_000) + 1);