fix JS testing decoder

This commit is contained in:
Martin Kavík 2024-07-08 14:30:49 +02:00
parent 7015cc9ce6
commit a60f4f9ec4
6 changed files with 31 additions and 15 deletions

View file

@ -24,6 +24,7 @@ tauri = { version = "=2.0.0-beta.22", features = ["macos-private-api", "linux-ip
tauri-plugin-window-state = "=2.0.0-beta.9"
tauri-plugin-dialog = "=2.0.0-beta.9"
once_cell = "1.19.0"
futures = "0.3.30"
# wasmtime = "22.0.0"
# wasmtime-wasi = "22.0.0"

View file

@ -79,7 +79,7 @@ pub async fn remove_all_decoders() -> RemovedDecodersCount {
// All Release
// FW.add_decoders(["../../test_files/components/rust_decoder/rust_decoder.wasm", "../../test_files/components/javascript_decoder/javascript_decoder.wasm", "../../test_files/components/python_decoder/python_decoder.wasm"])
pub async fn add_decoders(decoder_paths: Vec<DecoderPath>) -> AddedDecodersCount {
println!("decoders in Tauri: {decoder_paths:#?}");
println!("Decoders: {decoder_paths:#?}");
println!("Current dir: {:#?}", std::env::current_dir().unwrap());
let mut added_decoders_count = 0;

View file

@ -87,15 +87,27 @@ async fn load_signal_and_get_timeline(
var_format,
|mut value: String| {
Box::pin(async {
let decoders = component_manager::DECODERS.read().await;
let mut store_lock = component_manager::STORE.lock().await;
let mut store = store_lock.as_context_mut();
for decoder in decoders.iter() {
value = decoder
.component_decoder_decoder()
.call_format_signal_value(&mut store, &value)
.unwrap()
}
// We need to spawn a (non-runtime-specific?) blocking task before calling component methods to prevent this error:
// "Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks."
// @TODO Workaround? Is it a problem only for non-Rust components? Is it needed only when there is a problem in the component (e.g. "`Err` value: wasm trap: cannot enter component instance"?)
// let value = std::thread::spawn(move || {
// futures::executor::block_on(async move {
let decoders = component_manager::DECODERS.read().await;
let mut store_lock = component_manager::STORE.lock().await;
let mut store = store_lock.as_context_mut();
for decoder in decoders.iter() {
value = decoder
.component_decoder_decoder()
.call_format_signal_value(&mut store, &value)
// @TODO Resolve panic when running non-Rust components:
// `Err` value: wasm trap: cannot enter component instance
// https://github.com/bytecodealliance/wasmtime/issues/8670 ?
.unwrap()
}
// value
// })
// }).join().unwrap();
value
})
},