forked from StrafesNET/asset-tool
move file reading to worker threads
This commit is contained in:
parent
1164f8e12a
commit
759727d4e9
49
src/main.rs
49
src/main.rs
@ -1514,8 +1514,8 @@ async fn compile(config:CompileConfig)->AResult<()>{
|
||||
|
||||
let style=config.style;
|
||||
let exist_names=&exist_names;
|
||||
//thread the needle! follow the patch that dir takes!
|
||||
let u=futures::stream::unfold(dir,|mut dir1|async{
|
||||
futures::stream::unfold(dir,|mut dir1|async{
|
||||
//thread the needle! follow the path that dir takes!
|
||||
let ret1={
|
||||
//capture a scoped mutable reference so we can forward dir to the next call even on an error
|
||||
let dir2=&mut dir1;
|
||||
@ -1523,20 +1523,7 @@ async fn compile(config:CompileConfig)->AResult<()>{
|
||||
let ret2=if let Some(entry)=dir2.next_entry().await?{
|
||||
//cull early even if supporting things with identical names is possible
|
||||
if !exist_names.contains(entry.file_name().to_str().unwrap()){
|
||||
let met=entry.metadata().await?;
|
||||
//discern that bad boy
|
||||
let compile_class=match met.is_dir(){
|
||||
true=>locate_override_file(&entry,style).await?,
|
||||
false=>discern_file(&entry,style).await?,
|
||||
};
|
||||
//prepare data structure
|
||||
TooComplicated::Value((compile_class.blacklist,match compile_class.class{
|
||||
CompileClass::Folder=>PreparedData::Builder(rbx_dom_weak::InstanceBuilder::new("Folder").with_name(compile_class.name.as_str())),
|
||||
CompileClass::Script(source)=>PreparedData::Builder(script_builder("Script",compile_class.name.as_str(),source)),
|
||||
CompileClass::LocalScript(source)=>PreparedData::Builder(script_builder("LocalScript",compile_class.name.as_str(),source)),
|
||||
CompileClass::ModuleScript(source)=>PreparedData::Builder(script_builder("ModuleScript",compile_class.name.as_str(),source)),
|
||||
CompileClass::Model(buf)=>PreparedData::Model(rbx_xml::from_reader_default(std::io::Cursor::new(buf))?),
|
||||
}))
|
||||
TooComplicated::Value(entry)
|
||||
}else{
|
||||
TooComplicated::Skip
|
||||
}
|
||||
@ -1552,13 +1539,37 @@ async fn compile(config:CompileConfig)->AResult<()>{
|
||||
Ok(TooComplicated::Value(v))=>Some((Ok(Some(v)),dir1)),
|
||||
Err(e)=>Some((Err(e),dir1)),
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
//gotta spawn off the worker threads (Model is slow)
|
||||
.then(|bog|async{
|
||||
match bog{
|
||||
Ok(Some(entry))=>tokio::spawn(async move{
|
||||
let met=entry.metadata().await?;
|
||||
//discern that bad boy
|
||||
let compile_class=match met.is_dir(){
|
||||
true=>locate_override_file(&entry,style).await?,
|
||||
false=>discern_file(&entry,style).await?,
|
||||
};
|
||||
//prepare data structure
|
||||
Ok(Some((compile_class.blacklist,match compile_class.class{
|
||||
CompileClass::Folder=>PreparedData::Builder(rbx_dom_weak::InstanceBuilder::new("Folder").with_name(compile_class.name.as_str())),
|
||||
CompileClass::Script(source)=>PreparedData::Builder(script_builder("Script",compile_class.name.as_str(),source)),
|
||||
CompileClass::LocalScript(source)=>PreparedData::Builder(script_builder("LocalScript",compile_class.name.as_str(),source)),
|
||||
CompileClass::ModuleScript(source)=>PreparedData::Builder(script_builder("ModuleScript",compile_class.name.as_str(),source)),
|
||||
CompileClass::Model(buf)=>PreparedData::Model(rbx_xml::from_reader_default(std::io::Cursor::new(buf))?),
|
||||
})))
|
||||
}).await?,
|
||||
Ok(None)=>Ok(None),
|
||||
Err(e)=>Err(e),
|
||||
}
|
||||
})
|
||||
|
||||
//is this even what I want?
|
||||
let u=u.map(|f|async{f}).buffer_unordered(32);
|
||||
.map(|f|async{f}).buffer_unordered(32)
|
||||
|
||||
//begin processing immediately
|
||||
u.fold((&mut stack,&mut dom),|(stack,dom),bog:Result<_,anyhow::Error>|async{
|
||||
.fold((&mut stack,&mut dom),|(stack,dom),bog:Result<_,anyhow::Error>|async{
|
||||
//push child objects onto dom serially as they arrive
|
||||
match bog{
|
||||
Ok(Some((blacklist,data)))=>{
|
||||
|
Loading…
Reference in New Issue
Block a user