The problem does not occure on the first service

This commit is contained in:
Quentin 2022-06-03 15:41:40 +02:00
parent 0c5cea017b
commit e9c454edaf
Signed by: quentin
GPG key ID: E9602264D639FF68

View file

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