From 4444f64ee98f314938a383b4dfdf3cd74fd7e717 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 6 Apr 2023 07:25:24 +0000 Subject: fix(context): fix async sharing --- examples/windmark.rs | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'examples') diff --git a/examples/windmark.rs b/examples/windmark.rs index 7c46d9d..687704d 100644 --- a/examples/windmark.rs +++ b/examples/windmark.rs @@ -80,22 +80,22 @@ async fn main() -> Result<(), Box> { r.mount("/module", success!("This is a module!")); }); router.attach_async(Clicker::default()); - router.set_pre_route_callback(|context| { - info!( - "accepted connection from {} to {}", - context.tcp.peer_addr().unwrap().ip(), - context.url.to_string() - ) - }); - router.set_post_route_callback(|context, content| { - content.content = - content.content.replace("Welcome!", "Welcome to Windmark!"); - - info!( - "closed connection from {}", - context.tcp.peer_addr().unwrap().ip() - ) - }); + // router.set_pre_route_callback(|context| { + // info!( + // "accepted connection from {} to {}", + // context.tcp.peer_addr().unwrap().ip(), + // context.url.to_string() + // ) + // }); + // router.set_post_route_callback(|context, content| { + // content.content = + // content.content.replace("Welcome!", "Welcome to Windmark!"); + // + // info!( + // "closed connection from {}", + // context.tcp.peer_addr().unwrap().ip() + // ) + // }); router.add_header(|_| "```\nART IS COOL\n```\nhi".to_string()); router.add_footer(|_| "Copyright 2022".to_string()); router.add_footer(|context| { @@ -110,13 +110,6 @@ async fn main() -> Result<(), Box> { .with_mime("text/plain") .clone() }); - router.mount( - "/ip", - success!( - context, - format!("Hello, {}", context.tcp.peer_addr().unwrap().ip()) - ), - ); router.mount("/test", success!("hi there\n=> / back")); router.mount( "/temporary-failure", @@ -211,8 +204,8 @@ async fn main() -> Result<(), Box> { Response::success(*clicks) } }); - router.mount("/async-nothing", |_| { - async { Response::success("This is an async route.") } + router.mount("/async-nothing", |context| { + async move { Response::success(context.url.path()) } }); router.mount( "/async-macro", -- cgit v1.2.3