chemicstry / wasm_thread

A rust `std::thread` replacement for wasm32 target
Apache License 2.0
128 stars 20 forks source link

Uncaught RuntimeError: unreachable executed #22

Closed GetAGripGal closed 5 months ago

GetAGripGal commented 5 months ago

Any attempt to spawn a thread causes a RuntimeError. Below is my current code. This crashes both on firefox and chromium.

        // Spawns the process thread
        log::info!("Spawing thread");
        wasm_thread::spawn(move || {
            log::info!("Thread entered");
            wasm_bindgen_futures::spawn_local(async move {

                let stdout = stdout_thread.clone();
                let mut stdout = match stdout.try_lock() {
                    Ok(stdout) => stdout,
                    Err(_) => return,
                };

                // Wait until the context lock can be taken, then inform the manager the process has been stopped
                'lock: loop {
                    if let Ok(mut ctx) = context_thread.try_lock() {
                        for _ in 0..10 {
                            stdout.writeln("Hello, world!");
                            let Some(display) = ctx.display.as_ref() else {
                                continue;
                            };
                            let html = display.inner_html();
                            display.set_inner_html(&format!("{} Hello, {}!", html, id));
                        }
                        ctx.running = false;
                        break 'lock;
                    }
                }
            });
        });

I have also attempted a basic thread, this crashes aswell:

wasm_thread::spawn(move || {
    log::info!("Hi");
});

I am using wasm-bindgen with the es-module feature enabled

GetAGripGal commented 5 months ago

My aplogies! This was an issue on my end!

For those wondering, the issue was that i was missing the following headers in my server:

Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin