no spawn
This commit is contained in:
parent
9cb95c435a
commit
ed87fd17ea
20
src/main.rs
20
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<dyn std::error::Error>> {
|
||||
let archive = ZipFileReader::new(String::from(BASE_FILENAME)).await?;
|
||||
async fn process_file(
|
||||
archive: &ZipFileReader,
|
||||
index: usize,
|
||||
name: String,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let entry_reader = archive.entry_reader(index).await?;
|
||||
|
||||
// make output filename
|
||||
@ -255,7 +257,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
})
|
||||
.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<dyn std::error::Error>> {
|
||||
|
||||
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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user