From ed87fd17eab48b70b8835987f5168b062f02b410 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 12 Sep 2022 16:30:13 +0300 Subject: [PATCH] no spawn --- src/main.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 42e35a0..b6c4fbd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,6 @@ extern crate json; extern crate tokio; use async_zip::read::fs::ZipFileReader; -use futures::future; use std::path::PathBuf; use std::str::FromStr; use tokio::fs; @@ -221,8 +220,11 @@ async fn parse_file( Ok(ctx.data.clone()) } -async fn process_file(index: usize, name: String) -> Result<(), Box> { - let archive = ZipFileReader::new(String::from(BASE_FILENAME)).await?; +async fn process_file( + archive: &ZipFileReader, + index: usize, + name: String, +) -> Result<(), Box> { let entry_reader = archive.entry_reader(index).await?; // make output filename @@ -255,7 +257,6 @@ async fn main() -> Result<(), Box> { }) .map(|item| (item.0, item.1.name().to_string())) .collect(); - drop(archive); // check output directory match fs::metadata(OUTPUT_PATH).await { @@ -266,17 +267,10 @@ async fn main() -> Result<(), Box> { println!("processing {} files ...", source_files.len()); - let mut handles = vec![]; - for index in source_files { - let i = index.clone(); - let handle = tokio::spawn(async move { - process_file(i.0, i.1).await.unwrap(); - }); - handles.push(handle); + for i in source_files { + process_file(&archive, i.0, i.1).await?; } - future::join_all(handles).await; - println!("done"); Ok(()) }