From e9c454edaf117fd3fefa4b5263a458f207970287 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 3 Jun 2022 15:41:40 +0200 Subject: [PATCH] The problem does not occure on the first service --- examples/simple.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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);