diff options
| author | Fuwn <[email protected]> | 2023-04-04 09:12:11 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-04-04 09:12:11 +0000 |
| commit | bda843b8f911f379fd8d3af526b9e6619f6a5ca9 (patch) | |
| tree | e297caaf07d84f2ba9351cc440ffd0c1ec45aa69 /examples | |
| parent | feat(cargo): bump 0.2.5 -> 0.3.0 (diff) | |
| download | windmark-bda843b8f911f379fd8d3af526b9e6619f6a5ca9.tar.xz windmark-bda843b8f911f379fd8d3af526b9e6619f6a5ca9.zip | |
feat(route): native async route support !!
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/windmark.rs | 15 |
1 files changed, 15 insertions, 0 deletions
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<dyn std::error::Error>> { 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<dyn std::error::Error>> { ) } }); + 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 } |