From bda843b8f911f379fd8d3af526b9e6619f6a5ca9 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 4 Apr 2023 09:12:11 +0000 Subject: feat(route): native async route support !! --- examples/windmark.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'examples') diff --git a/examples/windmark.rs b/examples/windmark.rs index f6857e5..5ddf7a3 100644 --- a/examples/windmark.rs +++ b/examples/windmark.rs @@ -61,6 +61,7 @@ impl windmark::Module for Clicker { async fn main() -> Result<(), Box> { let mut error_count = 0; let mut router = Router::new(); + let async_clicks = std::sync::Arc::new(tokio::sync::Mutex::new(0)); router.set_private_key_file("windmark_private.pem"); router.set_certificate_file("windmark_public.pem"); @@ -198,6 +199,20 @@ async fn main() -> Result<(), Box> { ) } }); + router.mount_async("/async", move |_| { + let async_clicks = async_clicks.clone(); + + async move { + let mut clicks = async_clicks.lock().await; + + *clicks += 1; + + Response::success(*clicks) + } + }); + router.mount_async("/async-nothing", |_| { + async { Response::success("This is an async route.") } + }); router.run().await } -- cgit v1.2.3