MCPcopy Create free account
hub / github.com/actix/examples / parallel_weather

Function parallel_weather

databases/sqlite/src/main.rs:38–48  ·  view source on GitHub ↗

Version 2: Calls 4 queries in parallel, as an asynchronous handler Returning Error types turn into None values in the response

(db: web::Data<Pool>)

Source from the content-addressed store, hash-verified

36/// Version 2: Calls 4 queries in parallel, as an asynchronous handler
37/// Returning Error types turn into None values in the response
38async fn parallel_weather(db: web::Data<Pool>) -> Result<HttpResponse, AWError> {
39 let fut_result = vec![
40 db::execute(&db, Queries::GetTopTenHottestYears),
41 db::execute(&db, Queries::GetTopTenColdestYears),
42 db::execute(&db, Queries::GetTopTenHottestMonths),
43 db::execute(&db, Queries::GetTopTenColdestMonths),
44 ];
45 let result: Result<Vec<_>, _> = join_all(fut_result).await.into_iter().collect();
46
47 Ok(HttpResponse::Ok().json(result.map_err(AWError::from)?))
48}
49
50#[actix_web::main]
51async fn main() -> io::Result<()> {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected