mirror of
https://github.com/actix/examples
synced 2025-06-27 01:27:43 +02:00
@ -30,7 +30,7 @@ pub async fn execute(pool: &Pool, query: Queries) -> Result<Vec<WeatherAgg>, Err
|
||||
|
||||
web::block(move || {
|
||||
// simulate an expensive query, see comments at top of main.rs
|
||||
sleep(Duration::from_secs(2));
|
||||
sleep(Duration::from_secs(1));
|
||||
|
||||
match query {
|
||||
Queries::GetTopTenHottestYears => get_hottest_years(conn),
|
||||
|
@ -37,10 +37,10 @@ async fn asyncio_weather(db: web::Data<Pool>) -> Result<HttpResponse, AWError> {
|
||||
/// Returning Error types turn into None values in the response
|
||||
async fn parallel_weather(db: web::Data<Pool>) -> Result<HttpResponse, AWError> {
|
||||
let fut_result = vec![
|
||||
Box::pin(db::execute(&db, Queries::GetTopTenHottestYears)),
|
||||
Box::pin(db::execute(&db, Queries::GetTopTenColdestYears)),
|
||||
Box::pin(db::execute(&db, Queries::GetTopTenHottestMonths)),
|
||||
Box::pin(db::execute(&db, Queries::GetTopTenColdestMonths)),
|
||||
db::execute(&db, Queries::GetTopTenHottestYears),
|
||||
db::execute(&db, Queries::GetTopTenColdestYears),
|
||||
db::execute(&db, Queries::GetTopTenHottestMonths),
|
||||
db::execute(&db, Queries::GetTopTenColdestMonths),
|
||||
];
|
||||
let result: Result<Vec<_>, _> = join_all(fut_result).await.into_iter().collect();
|
||||
|
||||
|
Reference in New Issue
Block a user