diff --git a/examples/simple.rs b/examples/simple.rs index e9910a6..b423812 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -5,12 +5,14 @@ use boitalettres::server::accept::addr::{AddrIncoming, AddrStream}; use boitalettres::server::Server; use tracing_subscriber; + +use tokio::time::{sleep, Duration}; + async fn handle_req(req: Request) -> Result { use imap_codec::types::response::{Capability, Data}; tracing::debug!("Got request: {:#?}", req); - use tokio::time::{sleep, Duration}; println!("WILL SLEEP"); sleep(Duration::from_millis(100)).await; println!("DONE SLEEP"); @@ -31,10 +33,17 @@ async fn main() -> Result<()> { let make_service = tower::service_fn(|addr: &AddrStream| { tracing::debug!(remote_addr = %addr.remote_addr, local_addr = %addr.local_addr, "accept"); + async { - let service = tower::ServiceBuilder::new().service_fn(handle_req); + println!("222 WILL SLEEP"); + sleep(Duration::from_millis(100)).await; + println!("222 DONE SLEEP"); - futures::future::ok::<_, std::convert::Infallible>(service) + let service = tower::ServiceBuilder::new().service_fn(handle_req); + + let r: Result<_, boitalettres::errors::Error> = Ok(service); + r + } }); let server = Server::new(incoming).serve(make_service);