Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions hyperprocess_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -1309,18 +1305,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
}
Expand All @@ -1340,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;
}
}
Expand Down Expand Up @@ -1418,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) => {
Expand All @@ -1446,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;
}
}
Expand All @@ -1466,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);
Expand Down
17 changes: 16 additions & 1 deletion hyperware_app_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -186,6 +186,21 @@ pub enum AppSendError {
BuildError(BuildError),
}

pub async fn sleep(sleep_ms: u64) -> Result<(), AppSendError> {
let request = Request::to(("our", "timer", "distro", "sys"))
.body(timer::TimerAction::SetTimer(sleep_ms))
.expects_response((sleep_ms / 1_000) + 1);

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(());
}

pub async fn send<R>(request: Request) -> Result<R, AppSendError>
where
R: serde::de::DeserializeOwned,
Expand Down