The web server I posted on recently. My thinking is to use async for the network IO ( well Axum does all that for me anyway), but do the database query evaluation in sync code. My get handler currently looks like this:
/// Handler for http GET requests.
async fn h_get(
state: Extension<Arc<SharedState>>,
path: Path<String>,
params: Query<HashMap<String, String>>,
cookies: Cookies,
) -> ServerQuery {
// Build the ServerQuery.
let mut sq = ServerQuery::new();
sq.x.path = path.0;
sq.x.params = params.0;
sq.x.cookies = map_cookies(cookies);
let blocking_task = tokio::task::spawn_blocking(move ||
{
// GET requests should be read-only.
let stg = Box::new(state.stg.open_read());
let db = Database::new(stg, "");
db.run_timed("EXEC web.Main()", &mut *sq.x);
sq
});
blocking_task.await.unwrap()
}