Prepare the compiler to be async

This will allow the online editor to load imports from URL asynchroniously later

Since currently the compiler is only working on a single thread, and that we
never await on a future that could block, it is allowed to use the spin_on executor
This commit is contained in:
Olivier Goffart 2020-10-30 11:18:27 +01:00
parent a7abfea961
commit 359f42c5f7
22 changed files with 110 additions and 89 deletions

View file

@ -167,9 +167,14 @@ pub fn compile_with_config(
compiler_config.embed_resources = true;
}
};
let embed_resources = compiler_config.embed_resources;
let (doc, mut diag) =
sixtyfps_compilerlib::compile_syntax_node(syntax_node, diag, &compiler_config);
// 'spin_on' is ok here because the compiler in single threaded and does not block if there is no blocking future
let (doc, mut diag) = spin_on::spin_on(sixtyfps_compilerlib::compile_syntax_node(
syntax_node,
diag,
compiler_config,
));
if diag.has_error() {
let vec = diag.to_string_vec();
@ -207,7 +212,7 @@ pub fn compile_with_config(
write!(code_formater, "{}", generated).map_err(CompileError::SaveError)?;
println!("cargo:rerun-if-changed={}", path.display());
if !compiler_config.embed_resources {
if embed_resources {
for resource in doc.root_component.referenced_file_resources.borrow().keys() {
println!("cargo:rerun-if-changed={}", resource);
}