mirror of
https://github.com/actix/examples
synced 2024-11-23 22:41:07 +01:00
parent
fbd3b228e9
commit
d25d71111f
@ -17,8 +17,7 @@ This creates a sqlite database, weather.db, in the root.
|
||||
```bash
|
||||
# if ubuntu : sudo apt-get install libsqlite3-dev
|
||||
# if fedora : sudo dnf install libsqlite3x-devel
|
||||
cargo run (or ``cargo watch -x run``)
|
||||
# Started http server: 127.0.0.1:8080
|
||||
cargo run
|
||||
```
|
||||
|
||||
### web client
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user