1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00

remove boxes from weather queries

fixes #282
This commit is contained in:
Rob Ede 2022-02-18 03:13:49 +00:00
parent fbd3b228e9
commit d25d71111f
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
3 changed files with 6 additions and 7 deletions

View File

@ -17,8 +17,7 @@ This creates a sqlite database, weather.db, in the root.
```bash ```bash
# if ubuntu : sudo apt-get install libsqlite3-dev # if ubuntu : sudo apt-get install libsqlite3-dev
# if fedora : sudo dnf install libsqlite3x-devel # if fedora : sudo dnf install libsqlite3x-devel
cargo run (or ``cargo watch -x run``) cargo run
# Started http server: 127.0.0.1:8080
``` ```
### web client ### web client

View File

@ -30,7 +30,7 @@ pub async fn execute(pool: &Pool, query: Queries) -> Result<Vec<WeatherAgg>, Err
web::block(move || { web::block(move || {
// simulate an expensive query, see comments at top of main.rs // simulate an expensive query, see comments at top of main.rs
sleep(Duration::from_secs(2)); sleep(Duration::from_secs(1));
match query { match query {
Queries::GetTopTenHottestYears => get_hottest_years(conn), Queries::GetTopTenHottestYears => get_hottest_years(conn),

View File

@ -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 /// Returning Error types turn into None values in the response
async fn parallel_weather(db: web::Data<Pool>) -> Result<HttpResponse, AWError> { async fn parallel_weather(db: web::Data<Pool>) -> Result<HttpResponse, AWError> {
let fut_result = vec![ let fut_result = vec![
Box::pin(db::execute(&db, Queries::GetTopTenHottestYears)), db::execute(&db, Queries::GetTopTenHottestYears),
Box::pin(db::execute(&db, Queries::GetTopTenColdestYears)), db::execute(&db, Queries::GetTopTenColdestYears),
Box::pin(db::execute(&db, Queries::GetTopTenHottestMonths)), db::execute(&db, Queries::GetTopTenHottestMonths),
Box::pin(db::execute(&db, Queries::GetTopTenColdestMonths)), db::execute(&db, Queries::GetTopTenColdestMonths),
]; ];
let result: Result<Vec<_>, _> = join_all(fut_result).await.into_iter().collect(); let result: Result<Vec<_>, _> = join_all(fut_result).await.into_iter().collect();