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

@ -63,18 +63,17 @@ fn load(mut cx: FunctionContext) -> JsResult<JsValue> {
}
None => vec![],
};
let compiler_config = sixtyfps_compilerlib::CompilerConfiguration {
include_paths: &include_paths,
..Default::default()
};
let compiler_config =
sixtyfps_compilerlib::CompilerConfiguration { include_paths, ..Default::default() };
let source = std::fs::read_to_string(&path).or_else(|e| cx.throw_error(e.to_string()))?;
let (c, warnings) = match sixtyfps_interpreter::load(source, &path, compiler_config) {
(Ok(c), warnings) => (c, warnings),
(Err(()), errors) => {
errors.print();
return cx.throw_error("Compilation error");
}
};
let (c, warnings) =
match spin_on::spin_on(sixtyfps_interpreter::load(source, path.into(), compiler_config)) {
(Ok(c), warnings) => (c, warnings),
(Err(()), errors) => {
errors.print();
return cx.throw_error("Compilation error");
}
};
warnings.print();