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;
|
extern crate tokio;
|
||||||
|
|
||||||
use async_zip::read::fs::ZipFileReader;
|
use async_zip::read::fs::ZipFileReader;
|
||||||
use futures::future;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
@ -221,8 +220,11 @@ async fn parse_file(
|
|||||||
Ok(ctx.data.clone())
|
Ok(ctx.data.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn process_file(index: usize, name: String) -> Result<(), Box<dyn std::error::Error>> {
|
async fn process_file(
|
||||||
let archive = ZipFileReader::new(String::from(BASE_FILENAME)).await?;
|
archive: &ZipFileReader,
|
||||||
|
index: usize,
|
||||||
|
name: String,
|
||||||
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let entry_reader = archive.entry_reader(index).await?;
|
let entry_reader = archive.entry_reader(index).await?;
|
||||||
|
|
||||||
// make output filename
|
// 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()))
|
.map(|item| (item.0, item.1.name().to_string()))
|
||||||
.collect();
|
.collect();
|
||||||
drop(archive);
|
|
||||||
|
|
||||||
// check output directory
|
// check output directory
|
||||||
match fs::metadata(OUTPUT_PATH).await {
|
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());
|
println!("processing {} files ...", source_files.len());
|
||||||
|
|
||||||
let mut handles = vec![];
|
for i in source_files {
|
||||||
for index in source_files {
|
process_file(&archive, i.0, i.1).await?;
|
||||||
let i = index.clone();
|
|
||||||
let handle = tokio::spawn(async move {
|
|
||||||
process_file(i.0, i.1).await.unwrap();
|
|
||||||
});
|
|
||||||
handles.push(handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
future::join_all(handles).await;
|
|
||||||
|
|
||||||
println!("done");
|
println!("done");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user