Skip to content

Commit

Permalink
use tokio instead of threads
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhamel committed Nov 14, 2024
1 parent 493b880 commit 4151acb
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/utils/mtl.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use futures::future::join_all;
use geojson::GeoJson;
use rayon::prelude::*;
use reqwest;
use sqlx::postgres::Postgres;
use std::fs::File;
use std::io::Write;
use std::process::Command;
use std::str::FromStr;
use time::Date;
use tokio::runtime::Runtime;
use tokio::spawn;

use crate::db::road_work::{self, Roadwork};

Expand All @@ -34,13 +34,18 @@ pub async fn fetch_montreal_data(conn: &sqlx::Pool<Postgres>) {
})
.collect();

let rt = Runtime::new().unwrap();
let tasks = sms
.into_iter()
.map(|sm| {
let conn = conn.clone();
spawn(async move {
read_tile(&sm, &conn).await;
})
})
.collect::<Vec<_>>();

join_all(tasks).await;

sms.par_iter().for_each(|sm| {
rt.block_on(async move {
read_tile(sm, conn).await;
});
});
match std::fs::remove_dir_all("tiles") {
Ok(_) => {}
Err(e) => {
Expand Down

0 comments on commit 4151acb

Please sign in to comment.