Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tokio::spawn for service function #3

Merged
merged 1 commit into from
May 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ async fn run_server(listener: TcpListener, db: Arc<maxminddb::Reader<Mmap>>) ->
let io = TokioIo::new(stream);
let db = db.clone();

let service = service_fn(move |req| {
let db = db.clone();
let ip = req.uri().path().trim_start_matches('/').to_string();
tokio::spawn(async move {
let service = service_fn(move |req| {
let db = db.clone();
let ip = req.uri().path().trim_start_matches('/').to_string();

async move {
handle_request(&ip, db).await
async move {
handle_request(&ip, db).await
}
});


if let Err(err) = http1::Builder::new().serve_connection(io, service).await {
println!("Error serving connection: {:?}", err);
}
});

if let Err(err) = http1::Builder::new().serve_connection(io, service).await {
println!("Error serving connection: {:?}", err);
}
}
}

Expand Down
Loading